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

ドキュメントを見ると、Cocoaエラー513は次のことを意味します。

NSFileWriteNoPermissionError = 513,

だから基本的に私はiCloudに何かを書くためのアクセス権がありません... https: //developer.icloud.comを見ると、すべてが大丈夫のようです(ドキュメントフォルダがあります)。

私が間違っているのは何ですか?

4

1 に答える 1

0

私は、developer.icloud.comですべてが見栄えがするかもしれませんが、12月30/31日から断続的に動作しています。ここの開発者フォーラムで進行中の議論があります:

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

現時点では、AppleのiCloudサーバーの問題である可能性があるため、iCloudの問題を診断するのは困難です。一部の人々は(ディスカッションスレッドで)iCloudが以前よりもうまく機能しているように見えるので、今すぐアプリをもう一度テストする価値があるかもしれないと述べています。

于 2013-01-03T18:59:48.110 に答える