控制哪些URL由 WebView 打开(Controls which URLs the WebView itself can be navigated to. Applies to top-level navigations only.)。 如果想让Cordova的WebView能打开https://www.google.com,那么需要在config.xml里加上如下配置
控制哪些URL让系统去打开(Controls which URLs the app is allowed to ask the system to open.)。 比如 sms:*、tel:*、itms-services:* 等,这些可以让系统去打开。也可以让系统打开 http:*、https:* 的链接,这时系统会调用系统浏览器打开
+ (CDVIntentAndNavigationFilterValue) filterUrl:(NSURL*)url intentsWhitelist:(CDVWhitelist*)intentsWhitelist navigationsWhitelist:(CDVWhitelist*)navigationsWhitelist { // a URL can only allow-intent OR allow-navigation, if both are specified, // only allow-navigation is allowed BOOL allowNavigationsPass = [navigationsWhitelist URLIsAllowed:url logFailure:NO]; BOOL allowIntentPass = [intentsWhitelist URLIsAllowed:url logFailure:NO]; if (allowNavigationsPass && allowIntentPass) { return CDVIntentAndNavigationFilterValueNavigationAllowed; } elseif (allowNavigationsPass) { return CDVIntentAndNavigationFilterValueNavigationAllowed; } elseif (allowIntentPass) { return CDVIntentAndNavigationFilterValueIntentAllowed; } return CDVIntentAndNavigationFilterValueNoneAllowed; }
+ (BOOL)shouldOverrideLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType filterValue:(CDVIntentAndNavigationFilterValue)filterValue { NSString* allowIntents_whitelistRejectionFormatString = @"ERROR External navigation rejected - <allow-intent> not set for url='%@'"; NSString* allowNavigations_whitelistRejectionFormatString = @"ERROR Internal navigation rejected - <allow-navigation> not set for url='%@'"; NSURL* url = [request URL]; switch (filterValue) { case CDVIntentAndNavigationFilterValueNavigationAllowed: returnYES; case CDVIntentAndNavigationFilterValueIntentAllowed: // only allow-intent if it's a UIWebViewNavigationTypeLinkClicked (anchor tag) OR // it's a UIWebViewNavigationTypeOther, and it's an internal link if ([[selfclass] shouldOpenURLRequest:request navigationType:navigationType]){ [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil]; } // consume the request (i.e. no error) if it wasn't handled above returnNO; case CDVIntentAndNavigationFilterValueNoneAllowed: // allow-navigation attempt failed for sure NSLog(@"%@", [NSString stringWithFormat:allowNavigations_whitelistRejectionFormatString, [url absoluteString]]); // anchor tag link means it was an allow-intent attempt that failed as well if (UIWebViewNavigationTypeLinkClicked == navigationType) { NSLog(@"%@", [NSString stringWithFormat:allowIntents_whitelistRejectionFormatString, [url absoluteString]]); } returnNO; } }