有一个全是H5页面的项目,h5定义的导航栏高度比前端设置的要小,经查询WKwebview在加载第一个页面时不会去加载UserAgent,解决方法:
在AppDelegate.m 的- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions 里加入
//H5首页导航栏高度不对
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero];
NSString *userAgent = [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
NSString*newUserAgent = [userAgent stringByAppendingString:@"****"];//自定义需要拼接的字符串
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:newUserAgent, @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
[[NSUserDefaults standardUserDefaults] synchronize];
网友评论