这里正在创建我的数据库的备份。但我不想继续创建备份。我需要检查最近创建的备份数据库的 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];
}