我正在尝试更改我的数据库文件夹以与我今天的小部件共享我的应用数据库以用于我的应用的所有旧版本。在didfinishlaunchingwithoptions上,我打电话给" changeDatabase"功能:
-(void)changeDatabase
{
NSFileManager *fm = [NSFileManager defaultManager];
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *filePath = [documentsPath stringByAppendingPathComponent:@"123456.sqlite"];
NSString *destinationPath =[[[[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.123456.CdCTodayExtensionSharingDefaults"] absoluteString] stringByAppendingString:@"123456.sqlite"];
NSError *err;
if ([fm fileExistsAtPath:filePath])
{
[fm copyItemAtPath: filePath toPath: destinationPath error: &err];
[fm removeItemAtPath:filePath error:NULL];
}
NSLog(@"ERROR %@",err);
NSLog(@"%@*****%@",filePath,destinationPath);
}
但是我无法做到,错误日志是这样的:
Error Domain=NSCocoaErrorDomain Code=4 "The operation couldn’t be completed. (Cocoa error 4.)"
UserInfo=0x1700fd480
{
NSSourceFilePathErrorKey=/var/mobile/Containers/Data/Application/03504063-CB59-417E-B5E8-FC6CB9DBF3B2/Documents/123456.sqlite,
NSUserStringVariant=(Copy),
NSDestinationFilePath=file:///private/var/mobile/Containers/Shared/AppGroup/DB5F1F23-114B-4651-B206-D53EAA0A2CB5/123456.sqlite,
NSFilePath=/var/mobile/Containers/Data/Application/03504063-CB59-417E-B5E8-FC6CB9DBF3B2/Documents/123456.sqlite,
NSUnderlyingError=0x1702408a0 "The operation couldn’t be completed. No such file or directory"
}
/var/mobile/Containers/Data/Application/03504063-CB59-417E-B5E8-FC6CB9DBF3B2/Documents/123456.sqlite*****file:///private/var/mobile/Containers/Shared/AppGroup/DB5F1F23-114B-4651-B206-D53EAA0A2CB5/123456.sqlite
这很简单,但我不知道问题是什么。感谢所有SO社区。 p>