我将存储的图像和视频文件传递给:
PHLivePhoto.requestLivePhotoWithResourceFileURLs
并获取一个PHLivePhoto
可以在PHLivePhotoView
. 但我想知道,一旦我有了,PHLivePhoto
有没有办法将它保存到照片库中?
问问题
5556 次
2 回答
16
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);
}];
于 2015-10-02T16:44:53.010 回答
6
斯威夫特 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")
}
于 2017-02-03T22:10:56.713 回答