WKWebView加载网页时 js和css样式无法显示
出现如下图:
正确的应该是这样的:
各种debug搞了一天,加载paypal时需要系统的默认UA,需要给拼接带上
加载其他的网页就不需要默认的UA,paypal高级了
https://www.paypal.com/checkoutnow?token=1P81602698434142F
-(void)setUA{
[webView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id result, NSError *error) {
NSString *webViewAgent = result; // 20220914 不要拼接Q ------20230626需要拼接 不然pp的css加载不出来 坑点坑坑
// NSString *webViewAgent = @"";
webViewAgent = [webViewAgentstringByAppendingFormat:@" sxxxx_ios %@ chn/%@ UDID/%@ material/%@ OIJsVersion/%@ lang/%@ %@",kAppVersion,[[UIDevicecurrentDevice]channelId],[[UIDevicecurrentDevice]deviceId],[[UIDevicecurrentDevice]material],kOIJsVersion,locale,[[UIDevicecurrentDevice]platformString]];
NSDictionary*dictionnary = [[NSDictionaryalloc]initWithObjectsAndKeys:webViewAgent,@"UserAgent",nil];
[[NSUserDefaultsstandardUserDefaults]registerDefaults:dictionnary];
__weak__typeof(self)weakSelf =self;
[weakSelfsetCustomUA:webViewAgent];
}];
}
举个例:
CPU iPhone OS 16_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 xxxxx_i 1.10.3 chn/0 UDID/71435E8F5B544xxxx035187135 mxxxial/0 OIJsVersion/2.0.3 lang/ja_xx iPhone11" "133.106.47.66
默认的ua就是:CPU iPhone OS 16_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148
需要给拼接带上就可以。
网友评论