2

我正在尝试使用以下代码将文件复制到 iCloud:

    NSError *error;
    //My Image Source file
    NSURL *sourceURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"_219" ofType:@"jpg"]isDirectory:NO];
    NSLog(@"source: %@", sourceURL);

    NSFileManager *fileManager = [NSFileManager defaultManager];

   //Discovering iCloud URL
   NSURL *iCloudDocumentsURL = [[fileManager URLForUbiquityContainerIdentifier:nil] URLByAppendingPathComponent:@"Documents"];
   NSLog(@"iCloudDocumentsURL: %@", iCloudDocumentsURL);

   //Setting destination URL
   NSURL *destinationURL = [iCloudDocumentsURL URLByAppendingPathComponent:@"image.jpg"];
   NSLog(@"destination: %@", destinationURL);

   //Copy file to iCloud
   BOOL success = [fileManager setUbiquitous:YES itemAtURL:sourceURL destinationURL:destinationURL error:&error];

   if (!success) {
       @throw [NSException exceptionWithName:[error localizedDescription] reason:[error localizedFailureReason] userInfo:nil];
   }

当我运行此代码时,我得到以下结果:

        2012-12-31 15:15:30.888 iCloudTest[10614:907] source: file://localhost/var/mobile/Applications/B2202406-BEB8-41B6-A3C4-2327EFB85E54/iCloudTest.app/_219.jpg
        2012-12-31 15:15:31.108 iCloudTest[10614:907] iCloudDocumentsURL: file://localhost/private/var/mobile/Library/Mobile%20Documents/xxxxxxxx~com~gazapps~iCloudTest/Documents/
        2012-12-31 15:15:31.110 iCloudTest[10614:907] destination: file://localhost/private/var/mobile/Library/Mobile%20Documents/XXXXXXXX~com~gazapps~iCloudTest/Documents/image.jpg
        2012-12-31 15:15:31.122 iCloudTest[10614:907] *** Terminating app due to uncaught exception 'The operation couldn’t be completed. (Cocoa error 513.)', reason: '(null)'
        *** First throw call stack:
        (0x38c312a3 0x32f1897f 0xbb617 0x3a31058d 0x3a350d71 0x3a34cae5 0x3a38e1c9 0xad241 0x3a351ad1 0x3a35165b 0x3a349843 0x3a2f1c39 0x3a2f16cd 0x3a2f111b 0x371295a3 0x371291d3 0x38c06173 0x38c06117 0x38c04f99 0x38b77ebd 0x38b77d49 0x3a34847d 0x3a3452f9 0xacff9 0x3627cb20)
        libc++abi.dylib: terminate called throwing an exception

查看文档,可可错误 513 意味着:

NSFileWriteNoPermissionError = 513,

所以基本上我无权在 iCloud 上写东西......看看https://developer.icloud.com,一切似乎都很好(文档文件夹在那里)。

我做错了什么?

4

1 回答 1

0

自 12 月 30 日/31 日以来,iCloud 一直在间歇工作,尽管 developer.icloud.com 上的一切看起来都不错。这里的开发者论坛正在进行讨论:

https://devforums.apple.com/thread/176739?tstart=0

此时很难诊断 iCloud 问题,因为它可能只是 Apple 的 iCloud 服务器上的问题。一些人已经注意到(在讨论线程上)iCloud 现在似乎比以前工作得更好,所以现在可能值得再次测试您的应用程序。

于 2013-01-03T18:59:48.110 回答