requestRecordPermission does nothing

一曲冷凌霜 提交于 2019-11-30 22:41:47

问题


Since the update of iOS 7 there has been some changes with recording applications. I have an app that used to work with iOS 5 and 6, but when I tried to run it on iOS 7 - recording didn't respond.

I checked the internet and saw there's a new method that needs to be called. I tried to place this code in viewDidAppear:

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
    if([[AVAudioSession sharedInstance] respondsToSelector:@selector(requestRecordPermission:)])
    {
        [[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) {
            NSLog(@"permission : %d", granted);
        }];
    }
}

'granted' is always 1 although I didn't grant any permission nor saw any request popup.

Btw I'm trying to handle this using xcode 4.6.3. I made a category for AVAudioSession with requestRecordPermission method, since this method is available in iOS 7 only.

Thanks.


回答1:


I ran into the same problem while testing on iOS7 simulator, it looks like requestRecordPermission does not work in simulator and "granted" is always returned YES. You have to test it on a real device.

If you have tested it once on a device and responded to the permission popup then permission popup will not come again until a reset of location & privacy is done.

To reset Location & Privacy follow these steps

Go to Settings -> General -> Reset -> Reset Location & Privacy and then press "Reset Warnings" when asked.



回答2:


Once you gave Audio permission to the application. Your app will not show permission prompt again.

If you want to test it, change bundle ID of your app & try.




回答3:


same for iOS 8 Simulator. AVAudioSession.sharedInstance().requestRecordPermission always returns true.On the other hand when you call

UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString)!) 

to open settings of your application on the simulator, microphone is never listed there.That would need to be tested on a real device.




回答4:


Add Privacy - Microphone Usage Description in your info plist to give access for the app to ask for permissions. This was causing me Thread13: signal SIGABRT error. After this is done the error is solved automatically.



来源:https://stackoverflow.com/questions/18957643/requestrecordpermission-does-nothing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!