Last active
January 28, 2016 17:35
-
-
Save FlexMonkey/d2b1cbd7e1b2caf8d31b to your computer and use it in GitHub Desktop.
Synchronously create a UIImage from an UIImagePickerControllerReferenceURL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Could benefit from some defensive coding :) | |
import Photos | |
let url = info[UIImagePickerControllerReferenceURL] as! NSURL | |
let fetchResult = PHAsset.fetchAssetsWithALAssetURLs([url], options: nil) | |
let asset = fetchResult.firstObject as! PHAsset | |
let manager = PHImageManager.defaultManager() | |
let options = PHImageRequestOptions() | |
options.synchronous = true | |
options.networkAccessAllowed = true | |
var image: UIImage? | |
manager.requestImageForAsset(asset, | |
targetSize: CGSize(width: 640, height: 640), | |
contentMode: .AspectFill, | |
options: options, | |
resultHandler: { | |
(imageResult: UIImage?, properties: [NSObject: AnyObject]?) in | |
image = imageResult | |
}) | |
print(image) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment