Ei kuvausta

FKWebviewUtil.m 977B

123456789101112131415161718192021222324252627282930
  1. //
  2. // FKWebviewUtil.m
  3. // FirstLink
  4. //
  5. // Created by ascii on 16/4/26.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKWebviewUtil.h"
  9. #import "FKReachabilityUtil.h"
  10. @implementation FKWebviewUtil
  11. + (void)configUserAgent {
  12. UIWebView* webView = [[UIWebView alloc] initWithFrame:CGRectZero];
  13. NSString* userAgent = [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
  14. NSRange range = [userAgent rangeOfString:@"firstlinkapp"];
  15. if (range.length > 0) {
  16. userAgent = [userAgent substringToIndex:range.location - 1];
  17. }
  18. NSString *uaString = [NSString stringWithFormat:@"%@ firstlinkapp/%@ NetType/%@"
  19. , userAgent
  20. , [SystemUtil applicationVersion]
  21. , [FKReachabilityUtil sharedInstance].networkType4UA];
  22. [[NSUserDefaults standardUserDefaults] registerDefaults:@{@"UserAgent" : uaString, @"User-Agent" : uaString}];
  23. }
  24. @end