2016-07-08 80 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

是的,它與您要求的位置權限相同,您需要定義一次,並且您可以多次使用多個目的,您需要對權限進行通用描述。 –