Skip to content

Instantly share code, notes, and snippets.

@Koze
Last active September 19, 2017 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Koze/c34e24b7e86d21c5a8894962e5ebf8a8 to your computer and use it in GitHub Desktop.
Save Koze/c34e24b7e86d21c5a8894962e5ebf8a8 to your computer and use it in GitHub Desktop.
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