每次我的应用程序从新状态打开时,我都会收到这些警告...但我认为这是第一次打开应用程序时,它会复制sqlite数据库。
WARNING: Slow defaults initialization - setup took 0.027397 seconds
WARNING: Slow defaults access for key Internal took 0.094897 seconds, tolerance is 0.020000
以下是复制代码:
- (void) copyDatabaseIfNeeded {
//Using NSFileManager we can perform many file system operations.
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSString *dbPath = [self getDBPath];
BOOL success = [fileManager fileExistsAtPath:dbPath];
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"db.sqlite"];
if (success) {
success = [fileManager contentsEqualAtPath:defaultDBPath andPath:dbPath];
if (!success) {
BOOL isE = [fileManager removeItemAtPath:dbPath error:&error];
if (!isE)
NSAssert1(0, @"Failed to remove corrupt database file with message '%@'.", [error localizedDescription]);
}
}
if(!success) {
success = [fileManager copyItemAtPath:defaultDBPath toPath:dbPath error:&error];
if (!success)
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}
}
- (NSString *) getDBPath
{
//Search for standard documents using NSSearchPathForDirectoriesInDomains
//First Param = Searching the documents directory
//Second Param = Searching the Users directory and not the System
//Expand any tildes and identify home directories.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
//NSLog(@"dbpath : %@",documentsDir);
return [documentsDir stringByAppendingPathComponent:@"db.sqlite"];
}
如何阻止我的应用向我发出这些警告?这是复制SQLite数据库时的常规方法吗?我知道数据库只是偶尔复制一次,但我真的不喜欢在日志中看到警告。