Delete images in camera roll from code iOS

后端 未结 2 2080
深忆病人
深忆病人 2020-12-30 17:18

Is there a way to delete images (and videos) in camera roll in the photos app that my app didn\'t create. I know you can\'t delete things from Asset Library that your app di

2条回答
  •  隐瞒了意图╮
    2020-12-30 17:54

    Yep, you can do this in iOS 8 using Photos framework.

    For example if you have Assets URLs stored in NSArray *assetsURLs

    PHPhotoLibrary *library = [PHPhotoLibrary sharedPhotoLibrary];
        [library performChanges:^{
            PHFetchResult *assetsToBeDeleted = [PHAsset fetchAssetsWithALAssetURLs:assetsURLs options:nil];
            [PHAssetChangeRequest deleteAssets:assetsToBeDeleted];
        } completionHandler:^(BOOL success, NSError *error)
         {
             //do something here
        }];
    

    this code will ask user to confirm removal from Camera Roll.

提交回复
热议问题