2016-12-05 16 views
1

我在向iOS 10上的麥克風要求權限時遇到了一個奇怪的問題。我將適當的plist屬性(隱私 - 麥克風使用說明)碼。在我的手機上,麥克風可以工作/啓用,並且可以在手機的應用程序設置中看到它。但是,在朋友的電話上,麥克風要求許可,但話筒選項不會顯示在應用程序的設置中。我在這裏錯過了什麼,即使我正確設置了權限?爲什麼我的手機會在設置中顯示選項,但不是我朋友的手機?我有一個iPhone SE,我的朋友有一個iPhone 6s。iOS麥克風選項即使在授予權限的情況下也不在應用程序設置中

的plist屬性:

<key>NSMicrophoneUsageDescription</key> 
<string>Used to capture microphone input</string> 

代碼請求許可:

if ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio] == AVAuthorizationStatusAuthorized) { 
    [self configureMicrophone]; 
} 
else { 
    UIAlertController *deniedAlert = [UIAlertController alertControllerWithTitle:@"Use your microphone?" 
                     message:@"The FOO APP requires access to your microphone to work!" 
                    preferredStyle:UIAlertControllerStyleAlert]; 
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"Go to Settings" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action){ 
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; 
    }]; 
    [deniedAlert addAction:action]; 
    [self presentViewController:deniedAlert animated:YES completion:nil]; 
} 

謝謝!

+2

爲什麼人們反對投票一個非常好的問題嗎?問題很清楚,並提供了相關的細節。你還想要什麼? – rmaddy

回答

3

您的代碼不正確。您檢查用戶是否已經有權限。如果沒有,你不要求許可。您只需顯示一個提示即可進入設置頁面。但是如果您的應用永遠不會請求使用麥克風的權限,則設置頁面上不會有麥克風設置。

您需要實際請求權限的代碼。我有以下的代碼我用對付麥克風權限:

+ (void)checkMicrophonePermissions:(void (^)(BOOL allowed))completion { 
    AVAudioSessionRecordPermission status = [[AVAudioSession sharedInstance] recordPermission]; 
    switch (status) { 
     case AVAudioSessionRecordPermissionGranted: 
      if (completion) { 
       completion(YES); 
      } 
      break; 
     case AVAudioSessionRecordPermissionDenied: 
     { 
      // Optionally show alert with option to go to Settings 

      if (completion) { 
       completion(NO); 
      } 
     } 
      break; 
     case AVAudioSessionRecordPermissionUndetermined: 
      [[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) { 
       if (granted && completion) { 
        dispatch_async(dispatch_get_main_queue(), ^{ 
         completion(granted); 
        }); 
       } 
      }]; 
      break; 
    } 

} 

您可以致電此如下:

[whateverUtilClass checkMicrophonePermissions:^(BOOL allowed) { 
    if (allowed) { 
     [self configureMicrophone]; 
    } 
}]; 
+0

好吧,這是有道理的,但爲什麼它出現在我的手機? –

+0

我能想到的唯一一點是,您的應用程序曾確實要求獲得許可,並且已在您的設備上觸發。 – rmaddy

+0

啊我認爲這是有道理的。謝謝! –

相關問題