Delegate Method on WKUIDelegate

In the session, regarding prompting user for camera or microphone permission, the delegate method shown in the code snippet is the following:

func webView(_ webView: WKWebView, decideMediaCapturePermissionFor origin: WKSecurityOrigin, initiatedByFrame frame: WKFrameInfo, type: WKMediaCaptureType) async -> WKPermissionDecision {
		return type == .microphone ? .prompt : .deny
	}

But, I couldn't find this method in the documentation. Instead, I found this:

func webView(_ webView: WKWebView, 
requestMediaCapturePermissionFor origin: WKSecurityOrigin, initiatedByFrame frame: WKFrameInfo, type: WKMediaCaptureType, decisionHandler: @escaping (WKPermissionDecision) -> Void)

Which one is the latest? Thanks!

Answered by Apple Designer in 679035022

decideMediaCapturePermissionFor is the async version, which is shown in the demo. Gives a bit cleaner code than the decisionHandler version.

But they are the exact same, functionality-wise.

I'd expect async versions of decisionHandler APIs that are not currently documented to be documented soon.

Accepted Answer

decideMediaCapturePermissionFor is the async version, which is shown in the demo. Gives a bit cleaner code than the decisionHandler version.

But they are the exact same, functionality-wise.

I'd expect async versions of decisionHandler APIs that are not currently documented to be documented soon.

I am currently implementing this method with difficulties.

Its an Cordova Application. The method gets called, I call the decisionHandler with WKPermissionDecisionGrant, there is no Prompt in the Application, but I don't get any audio from the devices mic. I also don't see the orange dot on top which indicates microphone usage.

When I change the value of the decisionHandler to WKPermissionDecisionPrompt it works, however it is back to the annoying behaviour that always asks the user for consent even though he has given it a day (or so) ago.

I am working with Xcode 14 RC and iOS/iPadOS 15 RC

Here is the source Code:

- (void)webView:(WKWebView *)webView requestMediaCapturePermissionForOrigin:(WKSecurityOrigin *)origin initiatedByFrame:(WKFrameInfo *)frame type:(WKMediaCaptureType)type decisionHandler:(void (^)(WKPermissionDecision))decisionHandler {   decisionHandler(WKPermissionDecisionGrant); }

hi could you able to fix that? i am having similar problem in cordova app. would you mind share the filename, and code you added? thank you

this code works, tested with iOS 15

(void)webView:(WKWebView *)webView requestMediaCapturePermissionForOrigin:(WKSecurityOrigin *)origin initiatedByFrame:(WKFrameInfo *)frame type:(WKMediaCaptureType)type decisionHandler:(void (^)(WKPermissionDecision))decisionHandler API_AVAILABLE(ios(15.0)) API_AVAILABLE(ios(15.0)){  decisionHandler(WKPermissionDecisionGrant); }
Delegate Method on WKUIDelegate
 
 
Q