4

Hi I'm playing with the new photos framework for ios 8.0. I'm trying to delete an array of photos and here is the code:

    NSArray *toDeletePhotos = [photos valueForKey:@"asset"];
    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
        [PHAssetChangeRequest deleteAssets:toDeletePhotos];
    } completionHandler:^(BOOL success, NSError *error) {
        if (success) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [self refreshPhotosAfterDeleting];
            });
        }
    }];

I tested this on around 8 devices. 6 of them successfully deleted selected photos and 2 of them returned and error that says: Error Domain=NSCocoaErrorDomain Code=-1 "The operation couldn’t be completed. (Cocoa error -1.)" The two devices I tested on are 6+ and 5s. I couldn't figure out what error it is and wonder anyone could help me with this. Thanks!

Daniyar
  • 2,975
  • 2
  • 26
  • 39
naiyili
  • 51
  • 1
  • 5
  • Hi.I also got the same issue.Have you resolved it? – Imran Jun 23 '15 at 07:05
  • @Imran Yes. It turns out that when photos are streamed/synced from other devices, there's no way you can delete them without deleting them on iTunes/iCoud. So I added a filter so no streamed/synced photos are fetched. Hope that helps. – naiyili Jun 23 '15 at 23:45
  • Thanks for your response.Please add your comment in answer and close the question. – Imran Jun 24 '15 at 06:18

1 Answers1

1

so after a while I solved the problem my self. It turns out that when photos are streamed/synced from other devices, there's no way you can delete them without deleting them on iTunes/iCoud. So I added a filter so no streamed/synced photos are fetched. For more information please refer to: https://support.apple.com/en-us/HT204120. Hope this helps!

naiyili
  • 51
  • 1
  • 5