Take the 2-minute tour ×

I'm trying to copy a file to iCloud using the follow code:

    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];

When I run this code I have the following result:

        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

Looking at documentation, Cocoa error 513 means:

NSFileWriteNoPermissionError = 513,

So basically I'm without access to write stuff on iCloud... Looking at https://developer.icloud.com, everything seems to be ok (the documents folder is there).

What I'm doing wrong ?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

iCloud has been working intermittently since December 30/31, even though everything may look good on developer.icloud.com. There's a discussion going on at the developer forums here:


It's hard to diagnose iCloud issues at this point since it may just be problems on Apple's iCloud server. Some people have noted (on the discussion thread) that iCloud seems to be working better today than prior days so it may be worth testing your app again now.

share|improve this answer
Thanks for the information! A lot of developers having problems with iCloud... –  Sebastian Jan 5 '13 at 1:51

Your Answer


