How to get the user agent on iOS?

后端 未结 6 2024
天涯浪人
天涯浪人 2020-12-14 19:59

Is there a way on iOS to get the user agent of the device? I don\'t want to hard code it since I need the user agent for all devices and I need to append the user agent to a

6条回答
  •  误落风尘
    2020-12-14 20:48

    A simpler way to ascertain the user agent in iOS is to get it directly from a UIWebView using the accepted answer to this SO post. To quote that answer:

    The solution was to create a UIWebView and then just use javascript to pull out the user agent.

    UIWebView* webView = [[UIWebView alloc] initWithFrame:CGRectZero];
    NSString* secretAgent = [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
    

提交回复
热议问题