Last active
September 19, 2017 21:26
-
-
Save Koze/c34e24b7e86d21c5a8894962e5ebf8a8 to your computer and use it in GitHub Desktop.
iOS 11 UIImagePicker test
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
@import UIKit; | |
@import Photos; | |
@interface ViewController : UIViewController | |
@end |
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
#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