你是如何使用新的PHAsset内容在iOS上使用UIImagePickerController获取完整图像的URL,因为ALAssetLibrary的内容已被弃用?
答案 0 :(得分:0)
我很难找到答案,所以为了帮助将来的人,这里是我的代码,用于将实际文件URL用于使用内置iOS UIImagePickerController选择的照片。使用ALAsset URL获取PHAsset仍然有点紧张,如果你知道另一种方法,那么请分享。
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSURL* sourceURL = [info objectForKey:UIImagePickerControllerReferenceURL];
if (sourceURL != nil) {
PHAsset* asset = [[PHAsset fetchAssetsWithALAssetURLs:@[sourceURL] options:nil] lastObject];
PHContentEditingInputRequestOptions* assetOptions = [[PHContentEditingInputRequestOptions alloc] init];
[assetOptions setNetworkAccessAllowed:false];
[asset requestContentEditingInputWithOptions:assetOptions
completionHandler:^(PHContentEditingInput* contentEditingInput, NSDictionary* info) {
NSURL* fullImageURL = contentEditingInput.fullSizeImageURL;
printf("Hey, got the actual image URL: %s\n", [[fullImageURL absoluteString] UTF8String]);
}];
}
// ...finish and dismiss the UIImagePickerController
}