Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete iCloud documents?

Tags:

ios

iphone

icloud

I'm using a UIDocument with iCloud. I'm not using CoreData. What's the best way to delete a UIDocument?

like image 779
Adrian Sarli Avatar asked Apr 19 '12 03:04

Adrian Sarli


People also ask

What happens if I delete documents from iCloud?

You can delete files you no longer want to store in iCloud Drive. Important: When you delete a file from iCloud Drive on iCloud.com, it's also deleted from all your devices that have iCloud Drive turned on.

Can you delete documents from the cloud?

Select the file or files you want to delete. Select Delete. The files move to the Recycle bin.


1 Answers

Copied from the "Deleting a Document" section of the Document-Based App Programming Guide for iOS.

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
    NSFileCoordinator* fileCoordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
    [fileCoordinator coordinateWritingItemAtURL:fileURL options:NSFileCoordinatorWritingForDeleting
        error:nil byAccessor:^(NSURL* writingURL) {
        NSFileManager* fileManager = [[NSFileManager alloc] init];
        [fileManager removeItemAtURL:writingURL error:nil];
    }];
});

N.B.: "When you delete a document from storage, your code should approximate what UIDocument does for reading and writing operations. It should perform the deletion asynchronously on a background queue, and it should use file coordination."

like image 83
AlexChaffee Avatar answered Sep 21 '22 03:09

AlexChaffee