crud - iCloud files keep reappearing after deleting -


i have following setup: app writes uidocument instances icloud. files synced , works fine. when try delete them keep reappearing. before delete files close them. here code deletes files:

- (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 start                                              nsfilemanager* filemanager = [[nsfilemanager alloc] init];                                              nserror* error = nil;                                              [filemanager removeitematurl:writingurl error:&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();     } } } 

after method executed several nsmetadataquerydidfinishgatheringnotifications. first not contain deleted file. nsmetadataquerydidfinishgatheringnotification gets caught , contains deleted file again.

i can't find reason this. appreciated.

i faced similar issue. remove encapsulation of nsfilecoordinator instantiation gcd, able perform delete operation (despite  documentation it's preferable have operation in background thread, odd because doing causes unable-to-delete issue in first place)

void (^deletedocument)() = ^() {     nsfilecoordinator* filecoordinator = [[nsfilecoordinator alloc] initwithfilepresenter:nil];         [filecoordinator coordinatewritingitematurl:todelete             options:nsfilecoordinatorwritingfordeleting             error:nil             byaccessor:^(nsurl* writingurl) {             // simple delete start             nsfilemanager* filemanager = [[nsfilemanager alloc] init];             nserror* error = nil;             [filemanager removeitematurl:writingurl error:&error];              if (error) {             logerror(@"%s - error while deleting file: %@", __pretty_function__, error);             }              [_files removeobject:todelete];              if (completion) {             completion((error == nil));             }              [self startquery];         }]; }; 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -