【问题标题】:Save UIDocument to iCloud give me NSCocoaErrorDomain Code=4将 UIDocument 保存到 iCloud 给我 NSCocoaErrorDomain Code=4
【发布时间】:2013-10-29 00:38:24
【问题描述】:

在我的应用程序中,我想在 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

我不明白为什么不能在这个帐户上工作,而在其他工作上......有什么问题?我已经重新安装了设备中存在帐户问题的所有配置文件,但是没有用,知道吗?

【问题讨论】:

    标签: ios objective-c icloud uidocument


    【解决方案1】:

    我修复了删除应用程序的 iCloud 文件夹的问题,使用命令转到 Finder 中的文件夹:

    Users/"username"/.Library/Mobile Documents/"app folder"
    

    然后在这里我删除文件夹,这样我就解决了问题。

    【讨论】:

    • 如何进入该目录?目录 .Library 不在我的主目录中。
    猜你喜欢
    • 2013-08-16
    • 1970-01-01
    • 1970-01-01
    • 2021-04-14
    • 2013-12-30
    • 1970-01-01
    • 2014-04-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多