我在我的应用程序中使用带有 iCloud 的 coredata。我正在使用几个在 iOS 6.1.3 下运行良好的代码,但在使用 iOS 6.1.3 设备时不能编写文档并保存。
我正在使用 OSX 10.8.3 和 xcode 版本:4.6.2
使用 iOS 6.1.3 时,执行在下面给出的代码处停止 -
[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);
}];
整个代码如下:
-(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 ");
}
}];
}
任何人请帮助我。
并提前致谢。