Activating iPhone camera action crashes my app
本问题已经有最佳答案,请猛点这里访问。
奇怪的问题:
我的用户通过点击按钮拍照来激活iPhone相机。例如。轻按按钮,相机打开。直到昨天,下面的代码都可以正常工作(并且仍然可以在我自己的手机上运行)。但是,在我们测试组中其他所有人的电话上,只要轻按"相机"按钮,应用程序就会崩溃。知道为什么吗?请参阅下面的代码-我很困惑。注意:每个人都在运行iOS10。
ViewController.h
1 2 3 4 5 6 7 8 9 | #import <UIKit/UIKit.h> @interface ViewController : UIViewController <UITextFieldDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate> { } @property (strong, nonatomic) NSMutableArray *photoData; @property (weak, nonatomic) IBOutlet UIImageView *imageView; @end |
ViewController.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | - (IBAction)takePhoto:(id)sender { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; picker.allowsEditing = YES; picker.sourceType = UIImagePickerControllerSourceTypeCamera; [self presentViewController:picker animated:YES completion:NULL]; } - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *chosenImage = info[UIImagePickerControllerEditedImage]; self.imageView.image = chosenImage; [picker dismissViewControllerAnimated:YES completion:NULL]; } - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { [picker dismissViewControllerAnimated:YES completion:NULL]; } |
如果仅在
下添加
1 | Privacy - Photo Library Usage Description |
到您的
您可以参考此答案以获取更多键及其说明!