Granting File and camera permissions to WebView in SwiftUI

I am developing an app that uses an embedded WebView to show a web forum for users to interact with through the app. The forum (an SMF Forum) allows users to upload attachments to posts by accessing the file system or camera to take a photo but my app crashes because I don't have the proper permissions enabled. I'm trying to find some resources to help me implement the needed code to make this happen but I'm not sure where to look. Can anyone point me to some resources (or better, a code example) illustrating how this is done? I'm using the latest version of XCode and SwiftUI for my development work.

You need to create the keys for Privacy in info.plist.

  • For instance, for Camera, add an entry for Privacy - Camera Usage Description in info.plist

See doc https://developer.apple.com/documentation/avfoundation/capture_setup/requesting_authorization_to_capture_and_save_media

  • Then in code, you check for permission

See: https://stackoverflow.com/questions/67256632/swiftui-how-to-handle-camera-permissions

Granting File and camera permissions to WebView in SwiftUI
 
 
Q