gpt4 book ai didi

ios - 在 iPad 中启用相机限制会在打开相机时抛出 NSException

转载 作者:行者123 更新时间:2023-11-28 22:15:15 24 4
gpt4 key购买 nike

我在 iPad 的设置和隐私选项卡中启用了限制并禁止使用相机和 FaceTime,我禁用了对我的应用程序的照片的访问。

我正在使用以下代码打开相机和照片库,

//For camera
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
picker.allowsEditing = NO;
[self.view.window.rootViewController presentViewController:picker animated:YES completion:nil];

//For Photo library
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
picker.allowsEditing = NO;
[self.view.window.rootViewController presentViewController:picker animated:YES completion:nil];

打开照片库时,它会清楚地显示一条消息,表明访问被拒绝,可以在设置应用程序中更改。但是在打开相机时,应用程序崩溃并抛出错误,

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“源类型 1 不可用”
*** 首先抛出调用栈:
(0x30584f4b 0x3ac566af 0x32f56d69 0x1141d9 0x32ee4d03 0x32d2c713 0x32d2c6b3 0x32d2c691 0x32d1811f 0x32d2c107 0x32d2bdd9 0x32d 26e65 0x32cfc79d 0x32cfafa3 0x30550183 0x3054f653 0x3054de47 0x304b8c27 0x304b8a0b 0x3518c283 0x32d5c049 0xeff7d 0x3b15eab7)
libc++abi.dylib:以 NSException 类型的未捕获异常终止

如何解决这个问题?

最佳答案

您应该始终检查源类型是否可用:

来自 Apple UIImagePickerController文档化

Verify that the device is capable of picking content from the desired source. Do this calling the isSourceTypeAvailable: class method, providing a constant from the UIImagePickerControllerSourceType enumeration.

检查源是否可用,如:

if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary]) {
// UIImagePickerControllerSourceTypePhotoLibrary is available.
}

关于ios - 在 iPad 中启用相机限制会在打开相机时抛出 NSException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21876782/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com