ALAssetsLibrary这样的PHPhotoLibrary

ALAssetsLibrary这样的PHPhotoLibrary

本文介绍了如何使用像ALAssetsLibrary这样的PHPhotoLibrary的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于iOS9,不推荐使用 ALAssetsLibrary 。那么如何将其更改为 PHPPhotoLibrary 而不是 ALAssets

For iOS9, ALAssetsLibrary is deprecated. So how to change it as PHPPhotoLibrary instead of ALAssets?

if (RecordedSuccessfully && recording == NO) {
    //----- RECORDED SUCESSFULLY -----
    NSLog(@"didFinishRecordingToOutputFileAtURL - success");
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:outputFileURL])
    {
        [library writeVideoAtPathToSavedPhotosAlbum:outputFileURL
                                    completionBlock:^(NSURL *assetURL, NSError *error)
         {
             if (error)
             {

             }
         }];
    }

//我试过这个,但没有工作

// i have tried this, but didnt work

[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{

        PHAssetChangeRequest* createAssetRequest = [PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:outputFileURL];

        NSParameterAssert(createAssetRequest);
    }
                                      completionHandler:^(BOOL success, NSError *error) {}];
    }
}


推荐答案

// Save to the album
   __block PHObjectPlaceholder *placeholder;

    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
        PHAssetChangeRequest* createAssetRequest = [PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:outputFileURL];
        placeholder = [createAssetRequest placeholderForCreatedAsset];

    } completionHandler:^(BOOL success, NSError *error) {
        if (success)
        {
           NSLog(@"didFinishRecordingToOutputFileAtURL - success for ios9");
        }
        else
        {
            NSLog(@"%@", error);
        }
    }];

这篇关于如何使用像ALAssetsLibrary这样的PHPhotoLibrary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 21:45