How can I prevent IOS apps from resetting after changing permissions (such as Microphone, Camera, Photoes)?

238 views Asked by At

My question is similar to "How can I prevent iOS apps from resetting after changing Camera permissions?". But I don't understand the answer very well .

I set the microphone permission by the code as follow:

-(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;

}

then back to my app by clicking the return key in the status bar, my app will force a refresh and I will lose my place in the app.

I'm using an iPhone5 running IOS 9.3.3.

0

There are 0 answers