在我的应用程序中,我想在iCloud上编写文档,但是我的一个iCloud帐户有问题,这种情况是这样的:iCloud帐户A,一切正常,我可以写和读,用iPad和iPhone。iCloud帐户B,同上,我可以写和读。iCloud帐户C,不起作用,我无法写入和读取并给我错误。
这是一段代码:
NSURL *ubiqContainer = [[NSFileManager defaultManager]
URLForUbiquityContainerIdentifier:nil];
NSURL *ubiquitousPackage = [[ubiqContainer
URLByAppendingPathComponent:@"Documents"]
URLByAppendingPathComponent:kFILENAME];
MyDocument *mydoc = [[MyDocument alloc]
initWithFileURL:ubiquitousPackage];
self.mydoc = mydoc;
[mydoc saveToURL:[mydoc fileURL]
forSaveOperation:UIDocumentSaveForCreating
completionHandler:
^(BOOL success) {
//success is always FALSE for the Account C
}];
然后我已经实现了这种方法:
- (void) handleError:(NSError *)error userInteractionPermitted:(BOOL)userInteractionPermitted{
NSLog(@"error: %@", [error description]);
NSLog(@"permitted: %d", userInteractionPermitted);
}
这是日志:
error: Error Domain=NSCocoaErrorDomain Code=4 "The operation couldn’t be completed. (Cocoa error 4.)" UserInfo=0x15ef24f0 {NSFileNewItemLocationKey=file:///private/var/mobile/Applications/2A1F6A00-AA50-4D44-AFA1-89D0CA747EBB/tmp/(A%20Document%20Being%20Saved%20By%20My%20App)/MyApp.esd, NSFileOriginalItemLocationKey=file:///private/var/mobile/Library/Mobile%20Documents/EAYDD3QH5Q~com~mycompany~My-App/Documents/MyApp.esd, NSUnderlyingError=0x15e3c870 "The operation couldn’t be completed. (Cocoa error 4.)", NSURL=file:///private/var/mobile/Library/Mobile%20Documents/EAYDD3QH5Q~com~mycompany~My-App/Documents/MyApp.esd}
2013-10-20 16:53:24.358 My App[222:3707] permitted: 1
我不明白为什么在这个帐户上不起作用,而在其他作品上......怎么了?我已经重新安装了设备中的所有配置文件,但不起作用,知道吗?
我修复了删除应用程序的iCloud文件夹的问题,使用命令转到Finder中的文件夹:
Users/"username"/.Library/Mobile Documents/"app folder"
然后在这里我删除文件夹,这样我解决了问题。