0

ここで、データベースのバックアップを作成しています。しかし、私はバックアップを作成し続けたくありません。最近作成されたバックアップ データベースの NSModificationDate プロパティを確認する必要があり、データベースが変更された場合にのみ新しいバックアップを作成する必要があります。誰でもこれについて私を助けることができますか?

-(IBAction)createdb:(id)sender
{
DatabaseList = [[NSMutableArray alloc]init];

NSDate *currentDateTime = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MMddyyyyHHmmss"];
NSString *dateInStringFormated = [dateFormatter stringFromDate:currentDateTime];

dbNameString = [NSString stringWithFormat:@"UW_%@.db",dateInStringFormated];

NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentFolderPath = [searchPaths objectAtIndex: 0];
NSString *dbName = @"UnitWiseDB.db";
NSString *dbPath1 = [documentFolderPath stringByAppendingPathComponent:dbNameString];
NSString *backupDbPath = [documentFolderPath stringByAppendingPathComponent:dbName];

NSError *error = nil;

NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:backupDbPath error:&error];
NSLog(@"Persistent store size: %@ bytes", [fileAttributes objectForKey:NSFileSize]);
NSLog(@"Modification Date: %@ ",[fileAttributes objectForKey:NSFileModificationDate]);

if ( ![[NSFileManager defaultManager] fileExistsAtPath:dbPath1])
{
    [[NSFileManager defaultManager] copyItemAtPath:backupDbPath toPath:dbPath1 error:nil];
}
NSLog(@"DBPath.......%@",dbPath1);

NSFileManager *manager = [NSFileManager defaultManager];
NSArray *fileList = [manager contentsOfDirectoryAtPath:documentFolderPath error:nil];

for (NSString *s in fileList)
{
    NSLog(@"Backup.....%@", s);
    [DatabaseList addObject:s];
}

[ListViewTableView reloadData];

}
4

1 に答える 1

1

変更を確認する代わりに、trojanfoe で説明されている簡単なトリックを使用できます。

変更するときはいつでも、データベース内のレコードを追加/削除/編集することを意味し、BOOLフラグ = YES を設定してに保存しNSUSERDEFAULTS、バックアップを作成した後、フラグを NO に設定します。

于 2013-06-12T10:53:00.077 に答える