简体   繁体   English

在PHPhotoLibrary中,如何知道视频文件是否可以保存在iPhone上

[英]In PHPhotoLibrary, how to know whether video file can save on iPhone or not

I'm changing over from ALAssetsLibrary to PHPhotoLibrary and want to know whether or not video file can save or not. 我正在从ALAssetsLibrary切换到PHPhotoLibrary,并想知道视频文件是否可以保存。 In ALAssetsLibray , you know, we could know it before start saving video file with the API ALAssetsLibray中 ,您知道在开始使用API​​保存视频文件之前就可以知道它

- (BOOL)videoAtPathIsCompatibleWithSavedPhotosAlbum:(NSURL *)videoPathURL;

Does anyone knows the substitute API for videoAtPathIsCompatibleWIthSavedPhotoAlbum in PHPhotoLibrary ? 有谁知道PHPhotoLibraryvideoAtPathIsCompatibleWIthSavedPhotoAlbum的替代API?

Or do you know the exact error code which means that a video file cannot save on the iOS device ? 还是您知道确切的错误代码,这意味着视频文件无法保存在iOS设备上?

My code for saving video file is like below, 我保存视频文件的代码如下所示,

- (void)saveVideoFile:(NSURL *)videoURL completion:(savePhotoFileCompletion)completion
{
    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
            PHAssetChangeRequest *assetChangeRequest;
            assetChangeRequest = [PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:videoURL];

            PHAssetCollectionChangeRequest *assetCollectionChangeRequest =
                [PHAssetCollectionChangeRequest changeRequestForAssetCollection:self.assetCollection];
            [assetCollectionChangeRequest addAssets:@[ [assetChangeRequest placeholderForCreatedAsset] ]];

        }

        completionHandler:^(BOOL success, NSError *_Nullable error) {
            DBGLog(@"success=%@, error=%@", (success ? @"YES" : @"NO"), error);
            completion(success, error);
        }];
}

I found the question talking about the same issue. 我发现有关同一问题的问题。

How to use PHPhotoLibrary like ALAssetsLibrary 如何使用像ALAssetsLibrary这样的PHPhotoLibrary

But it doesn't refer to the exact answer. 但这并没有涉及确切的答案。

I asked my question to Apple with TSI. 我用TSI向苹果问了我的问题。 And their answer is to use the following API 他们的答案是使用以下API

AVAsset *avAsset = [AVAsset assetWithURL:[NSURL fileURLWithPath:videoPath]];
BOOL canSaveVideo = [avAsset isCompatibleWithSavedPhotosAlbum];

It seemed that I could get the correct compatibility. 看来我可以获得正确的兼容性。

One important point it that PHPhotoLibrary can save the video even if the value of canSaveVideo is NO. 重要的一点是,即使canSaveVideo值为NO,PHPhotoLibrary也可以保存视频。

Thank you. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM