我有一张照片,我希望我的用户能够在Instagram上分享,我需要获取照片的本地文件目录.
但是,我将图像作为PHAsset获取(而不是ALAsset,所有其他答案似乎涵盖了这个主题).
看看PHAsset文档,我看不到一个’本地目录’变量.
您是否知道如何使用新的ios8 Photo框架从用户相机胶卷获取照片的路径?
public func loadLastPhotoIntoGalleryIcon() { if(PHPhotoLibrary.authorizationStatus() != PHAuthorizationStatus.Authorized) { return } var fetchOptions:PHFetchOptions = PHFetchOptions() fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate",ascending: false)] var fetchResult:PHFetchResult = PHAsset.fetchAssetsWithMediaType(PHAssetMediaType.Image,options: fetchOptions) var lastAsset:PHAsset = fetchResult.firstObject as PHAsset var options:PHImageRequestOptions = PHImageRequestOptions() options.version = PHImageRequestOptionsVersion.Current PHImageManager.defaultManager().requestImageForAsset(lastAsset,targetSize: _view.getGalleryIconSize(),contentMode: PHImageContentMode.AspectFill,options: options) { (result,objects) -> Void in self._view.setGalleryIcon(result) } }
解决方法
使用内容编辑输入:
asset.requestContentEditingInputWithOptions(PHContentEditingInputRequestOptions()) { (input,_) in let url = input.fullSizeImageURL }
确保资产是PHAssetMediaType.Image,否则可能会在解包可选时崩溃.