我在我的应用程序中使用 coredata 和 icloud。当我在 iCloud 上创建 UIManagedDocument 并在 iPhone5 以外的设备上调试应用程序时,它工作正常。但是在 iPhone 上调试时,会出现如下错误:
6 月 26 日 15:49:49 Kumar-iPhone 图书馆员 [12461]:无法下载文件://localhost/private/var/mobile/Library/Mobile%20Documents/3JPA4W258L~com~leaf~Journal/COREDATABASE/ (0x8000000000000000):操作无法完成。(UBErrorDomain 错误 0。)��Jun 26 15:49:58 Kumar-iPhone librariand[12461]:无法下载文件://localhost/private/var/mobile/Library/Mobile%20Documents/3JPA4W258Lh~com~leaf~ Journal/Logs/ (0x8000000000000000):操作无法完成。(UBErrorDomain 错误 0。) ��Jun 26 15:49:58 Kumar-iPhone Journal[12554] : -PFUbiquityImportScanOperation main: CoreData: Ubiquity: Unable to get subpaths of root path (0): /private/var/mobile/Library /Mobile Documents/3JPA4W258L~com~leaf~Journal/Logs 错误:(null)userInfo:(null)��Jun 26 15:49:58 Kumar-iPhone Journal[12554]:
代码如下:
-(void)saveManagegDocument {
if(iCloud) {
NSError * error = nil;
[coordinator coordinateWritingItemAtURL:managedDoc.fileURL options:NSFileCoordinatorWritingForDeleting error:&error byAccessor:^(NSURL *newURL) {
NSError * delError = nil;
[[NSFileManager defaultManager] removeItemAtURL:newURL error:&delError];
//if(delError)
//NSLog(@"Error deleting data file .... , reason : %@",delError.localizedDescription);
}];
NSError * logerror = nil;
[coordinator coordinateWritingItemAtURL:[managedDoc.persistentStoreOptions valueForKey:NSPersistentStoreUbiquitousContentURLKey] options:NSFileCoordinatorWritingForDeleting error:&logerror byAccessor:^(NSURL *newURL) {
NSError * delError = nil;
[[NSFileManager defaultManager] removeItemAtURL:newURL error:&delError];
//if(delError)
//NSLog(@"Error deleting transaction file .... , reason : %@",delError.localizedDescription);
}];
}
[managedDoc saveToURL:managedDoc.fileURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) {
if (success) {
[managedDoc closeWithCompletionHandler:^(BOOL success) {
[managedDoc openWithCompletionHandler:^(BOOL success) {
[self performSelectorOnMainThread:@selector(documentReady) withObject:nil waitUntilDone:NO];
}];
}];
} else {
[[[UIAlertView alloc] initWithTitle:@"Could not save or open core data database." message:nil delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil] show];
// [self showMessage:@"Could not save or open core data database "];
//NSLog(@"Could not save or open core data database ");
}
}];
}
所以,如果你有,请写下答案?
谢谢。