How to use PHPhotoLibrary like ALAssetsLibrary

2019-01-25 08:02发布

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) {}];
    }
}

1条回答
劳资没心,怎么记你
2楼-- · 2019-01-25 08:41
// 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);
        }
    }];
查看更多
登录 后发表回答