/* @abstract Evaluates the given JavaScript string. @param javaScriptString The JavaScript string to evaluate. @param completionHandler A block to invoke when script evaluation completes or fails. @discussion The completionHandler is passed the result of the script evaluation or an error. */ - (void)evaluateJavaScript:(NSString *)javaScriptString completionHandler:(void (^ _Nullable)(_Nullable id, NSError * _Nullable error))completionHandler;
这个方法也可以用来解决Native调用JS的问题。
原生js中获取userAgent的方法就是”navigator.userAgent”。
2、修改userAgent;
1 2 3
/*! @abstract The custom user agent string or nil if no custom user agent string has been set. */ @property (nullable, nonatomic, copy) NSString *customUserAgent API_AVAILABLE(macosx(10.11), ios(9.0));