Skip to content

Commit

Permalink
Implement deletion of asset-library files
Browse files Browse the repository at this point in the history
  • Loading branch information
fxfactorial committed Aug 13, 2017
1 parent 37754c5 commit 4514b57
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Libraries/CameraRoll/CameraRoll.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ class CameraRoll {
return this.saveToCameraRoll(tag, 'photo');
}

static deletePhotos(photos: Array<string>) {
/** TODO error handling && check if they really do start with asset-library */
return RCTCameraRollManager.deletePhotos(photos);
}

/**
* Saves the photo or video to the camera roll / gallery.
*
Expand Down
18 changes: 18 additions & 0 deletions Libraries/CameraRoll/RCTCameraRollManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import <CoreLocation/CoreLocation.h>
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <Photos/Photos.h>

#import <React/RCTBridge.h>
#import <React/RCTConvert.h>
Expand Down Expand Up @@ -234,6 +235,23 @@ static void RCTResolvePromise(RCTPromiseResolveBlock resolve,
}];
}

RCT_EXPORT_METHOD(deletePhotos:(NSArray<NSString *>*)assets
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)
{
NSArray<NSURL *> *assets_ = [RCTConvert NSURLArray:assets];
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHFetchResult<PHAsset *> *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
Expand Down

0 comments on commit 4514b57

Please sign in to comment.