Reputation: 153
I have a basic iOS application written in Swift which loads an HTML5 website within WKWebView. I'm wondering if it's possible to access the microphone to record audio? I have requested permission explicitly to the user in the normal fashion for a native application, but am still unable to access the microphone.
Here's a snippet of what I've got:
class MainViewController: UIViewController, UIWebViewDelegate {
@IBOutlet weak var webView: UIWebView!
var session: AVAudioSession!
override func viewDidLoad() {
super.viewDidLoad()
session = AVAudioSession.sharedInstance()
if (session.responds(to: #selector(AVAudioSession.requestRecordPermission(_:)))) {
AVAudioSession.sharedInstance().requestRecordPermission({(granted: Bool)-> Void in
if granted {
print("granted")
do {
try self.session.setCategory(AVAudioSessionCategoryPlayAndRecord)
try self.session.setActive(true)
}
catch {
print("Couldn't set Audio session category")
}
} else{
print("not granted")
}
})
}
let url = URL(string: "https://www.somewebsite.com/")
let urlRequest = URLRequest(url: url!, cachePolicy: .returnCacheDataElseLoad, timeoutInterval: 0.0)
self.webView.loadRequest(urlRequest)
}
Upvotes: 4
Views: 2133