Ios 代码数据云错误
我正在努力将iCloud支持添加到基于ios 5的核心数据应用程序中。我可以在第一台设备上很好地安装应用程序,并将数据上传到iCloud。当我尝试在第二台设备上安装应用程序进行测试时,出现以下错误: 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[\uu NSCFDictionary setObject:forKey:]:尝试插入零密钥” 以下是我的相关iCloud代码: //**注意:如果您调整此代码以供自己使用,则必须更改此变量: NSString*iCloudEnabledAppID=@“com.strickelabs.iXercise” 据我所知,错误发生在addPersistentStoreWithType期间。我正在测试iPhone4S和iPad2。无论我安装应用程序的顺序如何,错误总是发生在第二台设备上 任何帮助都将不胜感激 只要有我的程序的iCloud实体并且该程序安装在设备上,就会出现错误Ios 代码数据云错误,ios,icloud,Ios,Icloud,我正在努力将iCloud支持添加到基于ios 5的核心数据应用程序中。我可以在第一台设备上很好地安装应用程序,并将数据上传到iCloud。当我尝试在第二台设备上安装应用程序进行测试时,出现以下错误: 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[\uu NSCFDictionary setObject:forKey:]:尝试插入零密钥” 以下是我的相关iCloud代码: //**注意:如果您调整此代码以供自己使用,则必须更改此变量: NSSt
编辑:看起来这是固定的。必须将.nosync作为核心数据的本地存储位置的后缀。因此存储的名称应为@“Xercise.sqlite.nosync”?因此存储的名称应为@“Xercise.sqlite.nosync”?
// ** Note: if you adapt this code for your own use, you should change this variable:
NSString *dataFileName = @"Xercise.sqlite";
// ** Note: For basic usage you shouldn't need to change anything else
NSString *iCloudDataDirectoryName = @"Data";
NSString *iCloudLogsDirectoryName = @"Logs";
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *localStore = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:dataFileName];
NSURL *iCloud = [fileManager URLForUbiquityContainerIdentifier:nil];
if (iCloud) {
NSLog(@"iCloud is working");
NSURL *iCloudLogsPath = [NSURL fileURLWithPath:[[iCloud path] stringByAppendingPathComponent:iCloudLogsDirectoryName]];
NSLog(@"iCloudEnabledAppID = %@",iCloudEnabledAppID);
NSLog(@"dataFileName = %@", dataFileName);
NSLog(@"iCloudDataDirectoryName = %@", iCloudDataDirectoryName);
NSLog(@"iCloudLogsDirectoryName = %@", iCloudLogsDirectoryName);
NSLog(@"iCloud = %@", iCloud);
NSLog(@"iCloudLogsPath = %@", iCloudLogsPath);
if([fileManager fileExistsAtPath:[[iCloud path] stringByAppendingPathComponent:iCloudDataDirectoryName]] == NO) {
NSError *fileSystemError;
[fileManager createDirectoryAtPath:[[iCloud path] stringByAppendingPathComponent:iCloudDataDirectoryName]
withIntermediateDirectories:YES
attributes:nil
error:&fileSystemError];
if(fileSystemError != nil) {
NSLog(@"Error creating database directory %@", fileSystemError);
}
}
NSString *iCloudData = [[[iCloud path]
stringByAppendingPathComponent:iCloudDataDirectoryName]
stringByAppendingPathComponent:dataFileName];
NSLog(@"iCloudData = %@", iCloudData);
NSMutableDictionary *options = [NSMutableDictionary dictionary];
[options setObject:[NSNumber numberWithBool:YES] forKey:NSMigratePersistentStoresAutomaticallyOption];
[options setObject:[NSNumber numberWithBool:YES] forKey:NSInferMappingModelAutomaticallyOption];
[options setObject:iCloudEnabledAppID forKey:NSPersistentStoreUbiquitousContentNameKey];
[options setObject:iCloudLogsPath forKey:NSPersistentStoreUbiquitousContentURLKey];
[psc lock];
[psc addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
URL:[NSURL fileURLWithPath:iCloudData]
options:options
error:nil];
[psc unlock];