Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
iOS 11 UIImagePicker test
@import UIKit;
@import Photos;
@interface ViewController : UIViewController
@end
#import "ViewController.h"
@interface ViewController () <UINavigationControllerDelegate, UIImagePickerControllerDelegate>
@end
@implementation ViewController
- (IBAction)showImagePicker:(id)sender
{
NSLog(@"authorizationStatus = %ld", [PHPhotoLibrary authorizationStatus]);
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
NSLog(@"%@", info);
{
NSURL *assetURL = info[UIImagePickerControllerReferenceURL];
PHFetchResult<PHAsset *> *result = [PHAsset fetchAssetsWithALAssetURLs:@[assetURL] options:nil];
PHAsset *asset = result.firstObject;
NSLog(@"%@ %@", result, asset);
}
{
UIImage *image = info[UIImagePickerControllerReferenceURL];
NSLog(@"%@", image);
}
{
NSURL *URL = info[UIImagePickerControllerImageURL];
UIImage *image = [UIImage imageWithContentsOfFile:URL.path];
NSLog(@"%@", image);
}
[picker dismissViewControllerAnimated:YES completion:nil];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment