2

I'm changing over from ALAssetsLibrary to PHPhotoLibrary and want to know whether or not video file can save or not. In ALAssetsLibray, you know, we could know it before start saving video file with the API

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

Does anyone knows the substitute API for videoAtPathIsCompatibleWIthSavedPhotoAlbum in PHPhotoLibrary ?

Or do you know the exact error code which means that a video file cannot save on the iOS device ?

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

But it doesn't refer to the exact answer.

Community
  • 1
  • 1
M.Masa
  • 532
  • 4
  • 20

1 Answers1

4

I asked my question to Apple with TSI. And their answer is to use the following 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.

Thank you.

M.Masa
  • 532
  • 4
  • 20