有没有办法将实时照片保存到照片库?
Is there a way to save a Live Photo to the Photo Library?
我正在将存储的图像和视频文件传递给:
PHLivePhoto.requestLivePhotoWithResourceFileURLs
并获得一个可以在 PHLivePhotoView
中显示的 PHLivePhoto
对象。但我想知道,一旦我有了 PHLivePhoto
,有没有办法将它保存到照片库?
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);
}];
Swift 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")
}
我正在将存储的图像和视频文件传递给:
PHLivePhoto.requestLivePhotoWithResourceFileURLs
并获得一个可以在 PHLivePhotoView
中显示的 PHLivePhoto
对象。但我想知道,一旦我有了 PHLivePhoto
,有没有办法将它保存到照片库?
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);
}];
Swift 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")
}