How to avoid app crash if info.plist doesn't contain certain key?

Viewed 107

I am building an SDK, and in there, I need user permission to record audio, and for that user should add Privacy - Microphone Usage Description in info.plist. I want to make sure the app doesn't crash even if the key is not added to info.plist, with some popup, that can alert user to add relative key in info.plist. Any help would be appreciated.

1 Answers

You can check whether the key is added or not by the bellow code by reading info.plist file.

if let permission = Bundle.main.object(forInfoDictionaryKey: "NSCameraUsageDescription") as? String {
   print(permission)
}

If permission is not there, we will not add code of request and show some alert like please add permission.

Also, there is one nice article that helps to identify missing permission before creating build.

https://medium.com/rosberryapps/swift-plist-and-two-smoking-scripts-94bb54cbeded

Related