激活 iPhone 相机操作会使我的应用程序崩溃
Activating iPhone camera action crashes my app
奇怪的问题:
我的用户通过点击按钮拍照来激活 iPhone 相机。例如。点击按钮,相机打开。直到昨天,下面的代码都运行良好(我自己仍然可以运行 phone)。但是,在我们测试组中其他所有人的 phone 上,只要点击相机按钮,应用就会崩溃。知道为什么吗?请参阅下面的代码 - 我很难过。 注:大家都是运行 iOS10.
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UITextFieldDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate> {
}
@property (strong, nonatomic) NSMutableArray *photoData;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end
ViewController.m
- (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];
}
如果它仅在 ios10
上崩溃,则可能是 privacy key setting
的问题,这在 ios10
和 xcode 8
中是强制性的。所以你需要在下面添加 key
,
Privacy - Photo Library Usage Description
加入你的info.plist
。我认为它可能会解决您的问题。否则你的代码是完美的。
您可以参考 以获取更多密钥及其说明!
奇怪的问题:
我的用户通过点击按钮拍照来激活 iPhone 相机。例如。点击按钮,相机打开。直到昨天,下面的代码都运行良好(我自己仍然可以运行 phone)。但是,在我们测试组中其他所有人的 phone 上,只要点击相机按钮,应用就会崩溃。知道为什么吗?请参阅下面的代码 - 我很难过。 注:大家都是运行 iOS10.
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UITextFieldDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate> {
}
@property (strong, nonatomic) NSMutableArray *photoData;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end
ViewController.m
- (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];
}
如果它仅在 ios10
上崩溃,则可能是 privacy key setting
的问题,这在 ios10
和 xcode 8
中是强制性的。所以你需要在下面添加 key
,
Privacy - Photo Library Usage Description
加入你的info.plist
。我认为它可能会解决您的问题。否则你的代码是完美的。
您可以参考