0

我的问题类似于“如何防止 iOS 应用在更改相机权限后重置? ”。但我不太明白答案。

我通过代码设置麦克风权限如下:

-(BOOL)canRecord { __block BOOL bCanRecord = NO;
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];

if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied)

{
    //prompt
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"setting permission" message:@"need microphone permission" preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction *settingAction = [UIAlertAction actionWithTitle:@"setting now" style:UIAlertActionStyleDefault handler:^(UIAlertAction * a){
        // jump to setting
        NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
        if ([[UIApplication sharedApplication] canOpenURL:url]) {

            if ([[[UIDevice currentDevice]systemVersion]floatValue]>10.0) {

                [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
            } else {
                [[UIApplication sharedApplication] openURL:url];
            } 
        }
    }];

    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"later" style:UIAlertActionStyleDefault handler:nil];
    [alertController addAction:settingAction];
    [alertController addAction:okAction];

    [self presentViewController:alertController animated:YES completion:nil];

}else{

    if ([[[UIDevice currentDevice]systemVersion]floatValue] >= 7.0) {
        AVAudioSession *audioSession = [AVAudioSession sharedInstance];
        [audioSession performSelector:@selector(requestRecordPermission:) withObject:^(BOOL granted) {
            if (granted) {
                bCanRecord = YES;
            } else {
                bCanRecord = NO;
            }
        }];
        //        }
    }
    NSLog(@"bCanRecord %d",bCanRecord);

}

return bCanRecord;

}

然后通过单击状态栏中的返回键返回我的应用程序,我的应用程序将强制刷新,我将失去我在应用程序中的位置。

我正在使用运行 IOS 9.3.3 的 iPhone5。

4

0 回答 0