4
-(void) checkAndCreateDatabase{

BOOL success;

NSFileManager *fileManager = [NSFileManager defaultManager];

success = [fileManager fileExistsAtPath:databasePath];

if(success) return;

NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName];


 NSError *errr;

 [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:&errr];

 NSLog( @"Error >>>>>>>> %@",errr);

}

使用上述代码在 iOS 5.0 模拟器中创建的数据库文件,但没有 sql 查询。如果使用 iOS 4.3 模拟器,它可以正常工作。运行 te app 时显示以下错误。

Error >>>>>>>> Error Domain=NSCocoaErrorDomain Code=516 "The operation couldn’t be completed. (Cocoa error 516.)" UserInfo=0x6a53860 {NSUserStringVariant=(
Copy
), NSFilePath=/Users/sj/Library/Application Support/iPhoneSimulator/5.0/Applications/D8BF5CC1-5690-4897-A3D7-252D915D399E/MyTest.app/MyTestDB.sql, NSDestinationFilePath=/Users/sj/Library/Application Support/iPhone Simulator/5.0/Applications/D8BF5CC1-5690-4897-A3D7-252D915D399E/Documents/MyTestDB.sql, NSUnderlyingError=0x6a65510 "The operation couldn’t be completed. File exists"}
4

0 回答 0