I get an unknown error with WKWebView on my Iphone.When try to Change the navigation link inside the view the destination link request camera and microphone permission. when try to view the alert between WKWebView and the device its crashed .
Cannot be called with asCopy = NO on non-main thread.
[UIView setAnimationsEnabled:] being called from a background thread. Performing any operation from a background thread on UIView or a subclass is not supported and may result in unexpected and insidious behavior. trace=(....)
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(nonnull WKNavigationAction *)navigationAction decisionHandler:(nonnull void (^)(WKNavigationActionPolicy))decisionHandler {
dispatch_async(dispatch_get_main_queue(), ^{
if (navigationAction.navigationType == WKNavigationTypeLinkActivated) {
if (navigationAction.request.URL) {
if (![navigationAction.request.URL.resourceSpecifier containsString:@"ex path"]) {
if ([[UIApplication sharedApplication] canOpenURL:navigationAction.request.URL]) {
//------>
UIApplication *application = [UIApplication sharedApplication];
[application openURL:navigationAction.request.URL options:@{} completionHandler:nil];
decisionHandler(WKNavigationActionPolicyCancel);
}else{
}
} else {
decisionHandler(WKNavigationActionPolicyAllow);
}
}
}
else if (navigationAction.request.URL && [[NSString stringWithFormat:@"%@",navigationAction.request.URL] rangeOfString:@"disconnectChat"].location != NSNotFound ){
decisionHandler(WKNavigationActionPolicyAllow);
[UIView animateWithDuration:0.5 animations:^{
self->_thankYouView.hidden = NO ;
} completion:^(BOOL finished) {
}];
}
else {
//------>
decisionHandler(WKNavigationActionPolicyAllow);
}
});
}
CodePudding user response:
Try use this
- (void) webView:(WKWebView *)webView
requestMediaCapturePermissionForOrigin:(WKSecurityOrigin *)origin
initiatedByFrame:(WKFrameInfo *)frame type:(WKMediaCaptureType)type
decisionHandler:(void (^)(WKPermissionDecision decision))decisionHandlerii
API_AVAILABLE(ios(15.0))
{
decisionHandler(WKPermissionDecisionGrant);
}