2016-07-08 77 views
20

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

然后我检查了隐私 - >设置以查看相机是否禁用了我的应用程序,但我的应用程序未在该部分中列出。请注意,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; 

} 

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

,并在其后进入块应用正确的崩溃requestAccessForMediaType:AVMediaTypeVideo

有太多的垃圾日志显示在控制台中,我无法找到崩溃消息。

编辑:我发现了一个选项,在Xcode禁用所有不必要的日志8回答甚至禁用回溯调试完毕后公布here.但还是Xcode中没有表现出任何崩溃日志。

我xcode8只是显示这个消息,并且应用程序只是退出:

App[1124:226447] [access] <private> 

我也试过试图请求媒体访问时,复位位置和隐私,但仍是应用程序崩溃。

任何想法为什么会发生这种情况?

+0

你有没有找到这方面的解决方案? –

+0

不,我仍然试图找出它 –

+0

就像你我没有得到任何崩溃日志! –

回答

27

我在我的info.plist文件中加入了"Privacy - Camera Usage Description",它现在可用。

+0

奇怪的是,我以前添加了这个,它没有工作,但它现在工作。 –

+1

太棒了! iOS 10需要它。 –

10

iOS 10您必须声明访问任何用户私有数据类型。您可以通过在应用程序的Info.plist中添加使用密钥来实现此目的。欲了解更多信息,请查看下面的截图。

您需要添加隐私 - 摄像机使用说明您的应用Info.plist的关键和它们的使用信息。

欲了解更多信息,请找到下面的GIF。

GIF

或者,如果你想通过info.plist中添加,那么你需要添加NSCameraUsageDescription关键。

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

<key>NSCameraUsageDescription</key> 
<string>Take the photo</string> 

请在下方找到GIF以获取更多信息。

GIF

欲了解更多信息,请查看link

7

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

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

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

下面是隐私其余规则:

<!-- 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> 

希望这有助于。 :)

+0

如果多次使用相机怎么办?就像我们有QR码和自拍功能一样。是否足够提及'这个应用程序使用Camera for multiple功能' – byJeevan

+0

是的,它与您要求的位置权限相同,您需要定义一次,并且您可以多次使用多个目的,您需要对权限进行通用描述。 –