[英]iOS Microphone Option Not in App Settings Even Though Permission was Given
在iOS 10上請求獲得麥克風的許可我有一個奇怪的問題。我把正確的plist屬性(隱私 - 麥克風使用說明)和通過代碼啟用它。 在我的手機上,麥克風工作/啟用,我在手機的應用程序設置中看到它。 但是,在朋友的手機上,麥克風會要求許可,但麥克風選項不會顯示在應用程序的設置中。 我在這里錯過了什么,即使我正確設置權限? 為什么我的手機會在設置中顯示選項而不是我朋友的手機? 我有一個iPhone SE,我的朋友有iPhone 6s。
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];
}
謝謝!
您的代碼不正確。 您檢查用戶是否已獲得權限。 如果沒有,則不要求許可。 您只需顯示一個警報,並選擇轉到設置頁面。 但如果您的應用從未請求使用麥克風的權限,則“設置”頁面上將不會設置麥克風。
您需要實際請求權限的代碼。 我有以下用於處理麥克風權限的代碼:
+ (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];
}
}];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.