0

How can delete one video from asset/album in iOS8

  1. When I use UIImagePickerController for purpose of selection
  2. then I select one Video from asset/album
  3. in Info Dictionary I got response on didFinishPickingMediaWithInfo method

     {
        UIImagePickerControllerMediaType = "public.movie";
    
        UIImagePickerControllerMediaURL = "file:///Users/appaspect2/Library/Developer/CoreSimulator/Devices/A61DFE3B-8BA0-4A18-939A-2B0BC2F6084E/data/Containers/Data/Application/69E55783-CB4F-4620-9C81-B3948F5A843B/tmp/trim.1202C1FA-6130-4BC7-AA31-391CC7E0D7B6.MOV";
    
        UIImagePickerControllerReferenceURL = "assets-library://asset/asset.MOV?id=189B68BD-17D0-4665-A065-11A40B0F2B25&ext=MOV";
    }
    
  4. I want to delete file this file which is select in UIImagePickerControllerReferenceURL or asset/album video

Himanshu
  • 4,327
  • 16
  • 31
  • 39
Gaurav
  • 168
  • 12

2 Answers2

0

AssestsLibrary do not have any such method. But after searching about this I found in ios8 deleting photos might be possible using the Photos Framework

Check the documentation of Photos Framework

For deleting assets refer to PHAssetChangeRequest

+ (void)deleteAssets:(id<NSFastEnumeration>)assets
Uttam Sinha
  • 722
  • 6
  • 9
  • if I have one URL "assets-library://asset/asset.MOV?id=189B68BD-17D0-4665-A065-11A40B0F2B25&ext=MOV" then how can pass it from this ? [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ [PHAssetChangeRequest deleteAssets:videoURL]; } completionHandler:^(BOOL success, NSError *error) { NSLog(@"Finished deleting asset. %@", (success ? @"Success." : error)); }]; – Gaurav Apr 08 '15 at 07:48
  • you can fetch PHAsset from file url and then pass it to deleteAssets method. I have not checked but think this is how it will work. Check this - http://stackoverflow.com/questions/28661938/retrieve-alasset-or-phasset-from-file-url – Uttam Sinha Apr 08 '15 at 08:07
  • I tried PHFetchResult *asset = [[PHAsset fetchAssetsWithALAssetURLs:@[info[@"UIImagePickerControllerReferenceURL"]] options:nil] firstObject]; NSLog(@"asset %@",asset); and Output I got : 79667072-F045-4B27-9B0E-75EACA6B9652/L0/001 mediaType=2/0, assetSource=0, (713x320), creationDate=2013-05-24 06:52:12 +0000, location=1, hidden=0, favorite=0 But when I pass it. It will be crash. – Gaurav Apr 08 '15 at 09:07
  • check this link - https://github.com/JaviSoto/iOS8-Runtime-Headers/blob/master/Frameworks/Photos.framework/PHAsset.h You have to get - (id)ALAssetURL; and pass this. Try this, hope it works. – Uttam Sinha Apr 08 '15 at 09:17
-1

Finally so much effort I am enable to delete file of asset/album video for iOS8 Only.

You can add this in didFinishPickingMediaWithInfo Method

PHFetchResult *asset = [[PHAsset fetchAssetsWithALAssetURLs:@[info[@"UIImagePickerControllerReferenceURL"]] options:nil] firstObject];
NSLog(@"asset %@",asset);

[self toggleFavoriteForAsset:(PHAsset *)asset];

and Add One Method For Delete Asset Video

- (void)toggleFavoriteForAsset:(PHAsset *)asset {
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
    // Create a change request from the asset to be modified.
    BOOL req = [asset canPerformEditOperation:PHAssetEditOperationDelete];
    if (req) {
        NSLog(@"true");
        [PHAssetChangeRequest deleteAssets:@[asset]];
    }
} completionHandler:^(BOOL success, NSError *error) {
    NSLog(@"Finished Delete asset. %@", (success ? @"Success." : error));
}];
}
Gaurav
  • 168
  • 12