Note that there are some explanatory texts on larger screens.

plurals
  1. POiCloud files keep reappearing after deleting
    primarykey
    data
    text
    <p>I have the following setup: My app writes UIDocument instances to iCloud. The files get synced and everything works fine. But when I try to delete them they keep reappearing. Before I delete the files I close them. Here is the code that deletes the files:</p> <pre><code>- (void)deleteDocumentWithName:(NSString*)name completion:(void (^)(BOOL success))completion { [self stopQuery]; NSURL* toDelete = [self URLForFileWithName:name]; UIDocument* doc = [[UIDocument alloc] initWithFileURL:toDelete]; void (^deleteDocument)() = ^() { // Wrap in file coordinator dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) { NSFileCoordinator* fileCoordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil]; [fileCoordinator coordinateWritingItemAtURL:toDelete options:NSFileCoordinatorWritingForDeleting error:nil byAccessor:^(NSURL* writingURL) { // Simple delete to start NSFileManager* fileManager = [[NSFileManager alloc] init]; NSError* error = nil; [fileManager removeItemAtURL:writingURL error:&amp;error]; if (error) { LogError(@"%s - error while deleting file: %@", __PRETTY_FUNCTION__, error); } dispatch_async(dispatch_get_main_queue(), ^{ [_files removeObject:toDelete]; if (completion) { completion((error == nil)); } [self startQuery]; }); }]; }); }; if (doc) { if (doc.documentState == UIDocumentStateNormal) { [doc closeWithCompletionHandler:^(BOOL success) { if (success) { deleteDocument(); } else { if (completion) { completion(NO); } } }]; } else { deleteDocument(); } } } </code></pre> <p>After this method was executed I get several NSMetadataQueryDidFinishGatheringNotifications. First it does not contain the deleted file. Then another NSMetadataQueryDidFinishGatheringNotification gets caught and it contains the deleted file again.</p> <p>I can't find the reason for this. Any help is appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COWhy do you set up a document before you delete it? That seems unnecessary. At a guess I would say you're deleting the file on disk, but UIDocument's autosave is kicking in and saving it again. Are you certain it's closed when you perform the delete? Also, it depends on how your query is set up, but stopping and starting the query while performing a delete seems unnecessary. Also stopQuery doesn't necessarily stop immediately (if you need this probably use disableUpdates instead) - from the docs for stopQuery: `The receiver first completes gathering any unprocessed results.`
      singulars
    2. COThanks for your response. I didn't figure out what the problem was but by removing the whole threading and background studd and by deleting the files directly vie the file manager solved the problem. for me the code seems a little bit buggy and dirty now. but hey, it works ;-)
      singulars
    3. COThat's good! If you see documents resurrecting in future, check you don't have an instance variable somewhere else that has an open copy of that same document. No matter how often you delete off disk, if there's a UIDocument instance hanging onto an open copy somewhere else in your app, auto-save is likely to resurrect it. You need to make sure that *instance* has it's copy of the file closed too. But IMHO threading and background stuff, while really cool when it works, can be a right pain in the ass to get working! There are so many gotchas to watch out for. It's worth it though.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload