diff --git a/Libraries/CameraRoll/CameraRoll.js b/Libraries/CameraRoll/CameraRoll.js index 596aec7e3b2f4b..eccad7d5265a92 100644 --- a/Libraries/CameraRoll/CameraRoll.js +++ b/Libraries/CameraRoll/CameraRoll.js @@ -133,6 +133,10 @@ class CameraRoll { return this.saveToCameraRoll(tag, 'photo'); } + static deletePhotos(photos: Array) { + return RCTCameraRollManager.deletePhotos(photos); + } + /** * Saves the photo or video to the camera roll / gallery. * diff --git a/Libraries/CameraRoll/RCTCameraRollManager.m b/Libraries/CameraRoll/RCTCameraRollManager.m index 64cf734b1ac3cd..4b6a78bde2c21b 100644 --- a/Libraries/CameraRoll/RCTCameraRollManager.m +++ b/Libraries/CameraRoll/RCTCameraRollManager.m @@ -12,6 +12,7 @@ #import #import #import +#import #import #import @@ -234,6 +235,27 @@ static void RCTResolvePromise(RCTPromiseResolveBlock resolve, }]; } +RCT_EXPORT_METHOD(deletePhotos:(NSArray*)assets + resolve:(RCTPromiseResolveBlock)resolve + reject:(RCTPromiseRejectBlock)reject) +{ + NSArray *assets_ = [RCTConvert NSURLArray:assets]; + [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ + PHFetchResult *fetched = + [PHAsset fetchAssetsWithALAssetURLs:assets_ options:nil]; + [PHAssetChangeRequest deleteAssets:fetched]; + } + completionHandler:^(BOOL success, NSError *error) { + if (success == YES) { + resolve(@(success)); + } + else { + reject(@"Couldn't delete", @"Couldn't delete assets", error); + } + } + ]; +} + static void checkPhotoLibraryConfig() { #if RCT_DEV