cfischer
cfischer

Reputation: 24912

setUbiquitous:itemAtURL:destinationURL:error: does not remove the item from iCloud

If I send the message

[[NSFileManager defaultManager] setUbiquitous:NO
                                    itemAtURL:url
                               destinationURL:iCloudURL
                                        error:&err]

to remove an item from iCloud, it doesn't actually delete the file on the Ubiquitous Container. Is this the expected behaviour?

The method returns NO and the error object contains

Error Domain=NSCocoaErrorDomain Code=512 "The operation couldn’t be completed. (Cocoa error 512.)"

UserInfo=0x20870970 {NSURL=file://localhost/var/mobile/Applications/168EE8CD-4CDF-49BE-AD88-1DC7DD9CF25F/Documents/test.txt,

NSUnderlyingError=0x20863a00 "The operation couldn’t be completed. (LibrarianErrorDomain error 2 - Cannot disable syncing on a unsynced item.)"}

Upvotes: 1

Views: 1339

Answers (3)

Scott Berrevoets
Scott Berrevoets

Reputation: 16946

The error is pretty clear. You're trying to delete an item from iCloud that's not in iCloud. When you want to delete an item from iCloud using setUbiquitous:..., the item URL (itemAtURL:) should be the iCloud URL. The destination URL can be something local (but is ignored if ubiquitous is set to NO).

Upvotes: 3

Tony
Tony

Reputation: 4591

To delete an item on iCloud, you can try this code:

NSError *err;
NSFileCoordinator* fileCoordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
[fileCoordinator coordinateWritingItemAtURL:_url
                                    options:NSFileCoordinatorWritingForDeleting
                                      error:&err
                                 byAccessor:^(NSURL* writingURL) {
                                           NSFileManager* fileManager = [NSFileManager defaultManager];
                                           [fileManager removeItemAtURL:writingURL error:nil];
                                 }];
[fileCoordinator autorelease];

Good luck!

Upvotes: 1

Sauceboi
Sauceboi

Reputation: 31

When specifying the "setubiquitous" parameter to "no", your destinationURL needs to be the local url, not the iCloud one. You have your URLs switched

Upvotes: 2

Related Questions