Search code examples
ioscocoa-touchios8photolibraryphotosframework

NSCocoaErrorDomain Code=-1 when deleting photos in user's photo library


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!


Solution

  • 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!