我将存储的图片和视频文件传递给:
PHLivePhoto.requestLivePhotoWithResourceFileURLs
并获取PHLivePhoto
对象,我可以在PHLivePhotoView
中显示该对象。但我想知道,一旦我有一个PHLivePhoto
有一种方法可以将它保存到照片库吗?
答案 0 :(得分:15)
NSURL *photoURL = ...;
NSURL *videoURL = ...;
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetCreationRequest *request = [PHAssetCreationRequest creationRequestForAsset];
//These types should be inferred from your files
//PHAssetResourceCreationOptions *photoOptions = [[PHAssetResourceCreationOptions alloc] init];
//photoOptions.uniformTypeIdentifier = @"public.jpeg";
//PHAssetResourceCreationOptions *videoOptions = [[PHAssetResourceCreationOptions alloc] init];
//videoOptions.uniformTypeIdentifier = @"com.apple.quicktime-movie";
[request addResourceWithType:PHAssetResourceTypePhoto fileURL:photoURL options:nil /*photoOptions*/];
[request addResourceWithType:PHAssetResourceTypePairedVideo fileURL:videoURL options:nil /*videoOptions*/];
} completionHandler:^(BOOL success, NSError * _Nullable error) {
NSLog(@"success? %d, error: %@",success,error);
}];
答案 1 :(得分:5)
斯威夫特3:
PHPhotoLibrary.shared().performChanges({
let request = PHAssetCreationRequest.forAsset()
request.addResource(with: .photo, fileURL: photoURL, options: nil)
request.addResource(with: .pairedVideo, fileURL: videoURL, options: nil)
}) { (success, error) in
print(success)
print(error?.localizedDescription ?? "error")
}