requestAccessForMediaType在iOS 10中崩溃

Tej*_*uri 20 objective-c card.io ios10 xcode8-beta2

在我的应用程序中,我使用card.io扫描信用卡.它在iOS 9中运行良好.在iOS 10中,应用程序崩溃,我无法在xcode 8 beta 2控制台中找到崩溃日志,因为它会抛出大量垃圾邮件.

然后我检查了隐私 - >设置以查看我的应用程序是否禁用了相机,但我的应用程序未列在该部分中.请注意,iOS 10并未授权我的应用程序使用相机.

我使用以下代码来请求权限:

-(BOOL)checkCameraPermissions{

    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    if(authStatus == AVAuthorizationStatusAuthorized)
    {
        // start card-io
        return YES;
    }
    else if(authStatus == AVAuthorizationStatusNotDetermined)
    {

        [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted)
         {
             if(granted)
             {
                 //Start card-io
                 [self testIsNewCard];
             }

         }];
    }
    else if (authStatus == AVAuthorizationStatusRestricted)
    {
        //Alert
        // Alert camera denied

        UIAlertController *aCon=[UIAlertController alertControllerWithTitle:@"Camera denied" message:@"Camera cannot be used" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *ok =[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [aCon dismissViewControllerAnimated:YES completion:nil];
        }];
        [aCon addAction:ok];
        [self presentViewController:aCon animated:YES completion:nil];

        return NO;

    }

    return NO;

}
Run Code Online (Sandbox Code Playgroud)

当我运行此代码时,authStatus返回为 AVAuthorizationStatusNotDetermined

并且应用程序在进入块后立即崩溃 requestAccessForMediaType:AVMediaTypeVideo

在控制台中显示了很多垃圾日志,我无法找到崩溃消息.

编辑:我找到一个选项来禁用xcode 8中所有不必要的日志.答案发布在这里.但是,即使禁用了回溯调试,xcode仍然没有显示任何崩溃日志.

我的xcode8只显示此消息,应用程序退出:

  App[1124:226447] [access] <private>
Run Code Online (Sandbox Code Playgroud)

我还尝试重置位置和隐私,但在尝试请求媒体访问时,应用程序仍然崩溃.

任何想法为什么会这样?

pul*_*ife 27

我将"Privacy - Camera Usage Description" 密钥添加到我的info.plist文件中,现在可以使用了.


Ram*_*rma 11

iOS 10您必须声明访问任何用户隐私数据的类型.您可以通过向应用添加使用密钥来执行此操作Info.plist.有关更多信息,请查看以下屏幕截图.

您需要将隐私 - 相机使用说明密钥添加到您应用的Info.plist及其使用信息中.

有关更多信息,请参阅以下GIF.

GIF

或者,如果要通过info.plist添加,则需要添加NSCameraUsageDescription键.

只需复制并粘贴到info.plist中的字符串下面即可.

<key>NSCameraUsageDescription</key>
<string>Take the photo</string>
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅以下GIF.

GIF

有关更多信息,请查看链接.


Aad*_*ani 7

iOS 10继续实施隐私政策,并实施了新的隐私规则.我们应该记得在下一个项目中实施它们.

对于您的问题,您需要添加以下行 info.plist

<!--  Camera -->
<key>NSCameraUsageDescription</key>
<string><Your description goes here></string>
Run Code Online (Sandbox Code Playgroud)

以下是其他隐私规则:

<!--  Photo Library -->
<key>NSPhotoLibraryUsageDescription</key>
<string><Your description goes here></string>

<!--  Camera -->
<key>NSCameraUsageDescription</key>
<string><Your description goes here></string>

<!--  Microphone -->
<key>NSMicrophoneUsageDescription</key>
<string><Your description goes here></string>

<!--  Location -->
<key>NSLocationUsageDescription</key>
<string><Your description goes here></string>

<!--  Location When In Use -->
<key>NSLocationWhenInUseUsageDescription</key>
<string><Your description goes here></string>

<!--  Location Always -->
<key>NSLocationAlwaysUsageDescription</key>
<string><Your description goes here></string>

<!--  Calendars -->
<key>NSCalendarsUsageDescription</key>
<string><Your description goes here></string>

<!-- ? Reminders -->
<key>NSRemindersUsageDescription</key>
<string><Your description goes here></string>

<!--  Motion -->
<key>NSMotionUsageDescription</key>
<string><Your description goes here></string>

<!--  Health Update -->
<key>NSHealthUpdateUsageDescription</key>
<string><Your description goes here></string>

<!--  Health Share -->
<key>NSHealthShareUsageDescription</key>
<string><Your description goes here></string>

<!-- ? Bluetooth Peripheral -->
<key>NSBluetoothPeripheralUsageDescription</key>
<string><Your description goes here></string>

<!--  Media Library -->
<key>NSAppleMusicUsageDescription</key>
<string><Your description goes here></string>
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助.:)