作为我的应用程序启动的一部分,我将包文件复制到我的文档目录。从主包复制创建文件大小为零kb
这对我的四个文件中的三个很好,但第四个创建一个零KB文件。
在iOS 5.0 sim上运行。我已经清理了几次这个版本,并检查了文件名的大写字母是否正确。
的文件出现在目录中,但零KB,应该是24K
知道的任何帮助。
-(BOOL) CheckDBs: (NSString *)dbname
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *dbPath = [documentsDir stringByAppendingPathComponent:dbname];
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL success = [fileManager fileExistsAtPath: dbPath];
NSLog(@"AppDelegate CheckDatabase: %@ = %i", dbPath, success);
if (success) {
//NSLog(@"return YES");
return YES;
}
else {
return NO;
}
} // Complete - checks if files exist in the User Documents directory
-(void) copyDBs: (NSString *) dbname
{
//Using NSFileManager we can perform many file system operations.
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *dbPath = [documentsDir stringByAppendingPathComponent:dbname];
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:dbname];
BOOL success = [fileManager copyItemAtPath:defaultDBPath toPath:dbPath error:&error];
if (success) {
// Version 4.0 code
//NSDictionary *attribs = [NSDictionary dictionaryWithObject:NSFileProtectionComplete forKey:NSFileProtectionKey];
//success = [fileManager setAttributes:attribs ofItemAtPath:dbPath error:&error];
NSLog(@"AppDelegate copyDatase: %@ = %d", dbPath, success);
}
//NSLog(@"AppDelegate copyDatase: %@ = %d", dbPath, success);
if (!success) {
NSLog(@"Failed to copy database: '%@'", [error localizedDescription]);
// NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}
}
包含有问题的代码,所以我们可以看到的部分是什么你做错了。 – WrightsCS
包含代码一件事日志给我一个1(即该文件存在于路径位置,我称之为\t dbname = @“UserProfile.db”; \t if(![self CheckDBs:dbname]){//检查User.db是否存在于Documents目录中 \t \t [self copyDBs:dbname]; //拷贝捆绑的数据库 \t} –