- (IBAction)actionPhoto:(id)sender //------------------------------------------------------------------------------------------------------------------------------------------------- { PresentPhotoLibrary(self, YES); } #pragma mark - UIImagePickerControllerDelegate //------------------------------------------------------------------------------------------------------------------------------------------------- - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info //------------------------------------------------------------------------------------------------------------------------------------------------- {………………}
//------------------------------------------------------------------------------------------------------------------------------------------------- BOOL PresentPhotoLibrary(id target, BOOL canEdit) //------------------------------------------------------------------------------------------------------------------------------------------------- { if (([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary] == NO && [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum] == NO)) return NO; //--------------------------------------------------------------------------------------------------------------------------------------------- NSString *type = (NSString *)kUTTypeImage; UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; //--------------------------------------------------------------------------------------------------------------------------------------------- if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary] && [[UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary] containsObject:type]) { imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; imagePicker.mediaTypes = [NSArray arrayWithObject:type]; } else if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum] && [[UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeSavedPhotosAlbum] containsObject:type]) { imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; imagePicker.mediaTypes = [NSArray arrayWithObject:type]; } else return NO; //--------------------------------------------------------------------------------------------------------------------------------------------- imagePicker.allowsEditing = canEdit; imagePicker.delegate = target; [target presentViewController:imagePicker animated:YES completion:nil]; //--------------------------------------------------------------------------------------------------------------------------------------------- return YES; }