October 2013
Intermediate to advanced
1053 pages
28h 7m
English
You want users to be able to pick a photo or a video from their photo library and use it in your application.
Use the UIImagePickerControllerSourceTypePhotoLibrary
value for the source type of your UIImagePickerController and the kUTTypeImage or kUTTypeMovie value, or both, for the
media type, like so:
-(BOOL)isPhotoLibraryAvailable{return[UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary];}-(BOOL)canUserPickVideosFromPhotoLibrary{return[selfcameraSupportsMedia:(__bridgeNSString*)kUTTypeMoviesourceType:UIImagePickerControllerSourceTypePhotoLibrary];}-(BOOL)canUserPickPhotosFromPhotoLibrary{return[selfcameraSupportsMedia:(__bridgeNSString*)kUTTypeImagesourceType:UIImagePickerControllerSourceTypePhotoLibrary];}-(void)viewDidAppear:(BOOL)animated{[superviewDidAppear:animated];staticBOOLbeenHereBefore=NO;if(beenHereBefore){/* Only display the picker once as the viewDidAppear: method getscalled whenever the view of our view controller gets displayed */return;}else{beenHereBefore=YES;}if([selfisPhotoLibraryAvailable]){UIImagePickerController*controller=[[UIImagePickerControlleralloc]init];controller.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;NSMutableArray*mediaTypes=[[NSMutableArrayalloc]init];if([selfcanUserPickPhotosFromPhotoLibrary]){[mediaTypesaddObject:(__bridgeNSString*)kUTTypeImage ...
Read now
Unlock full access