v1.0.0
{"appName":"快乐星球-默认应用","status":"normal","developerId":"UOwxZPvWOsDQR7bZOIk4i9__xHe99h2-","token":"c8fb526e62e1bb4e2eaa9df326917abab1c948c58ea23b82e1ad87a5380d029e"}
注:xxx表示后台为每一个应用分配一个channel,请加载正确的channel
mWebView.loadUrl("https://sso.geovisearth.com/mobile/login?channel=xxx");
WebSettings settings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.addJavascriptInterface(this, "nativeWebView");
@JavascriptInterface
public void postMessage(String dataStr) {
Log.d("postMessage",dataStr);
}
WKWebViewConfiguration * configuration = [[WKWebViewConfiguration alloc] init];
configuration.userContentController = [[ZKWKUserContentController alloc] initWithViewController:wself];
self.webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration];
NSURL * url = [NSURL URLWithString:self.url];
[self.webView loadRequest:[[NSURLRequest alloc] initWithURL:@"https://sso.geovisearth.com/mobile/login?channel=xxx" cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:30]];
[self addScriptMessageHandler:self name:@"nativeWebView"];
#pragma mark - WKScriptMessageHandler JS回调方法
- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message{
SEL s = NSSelectorFromString([message.name stringByAppendingString:@":"]);
if ([self respondsToSelector:s]) {
IMP imp = [self methodForSelector:s];
void (*func)(id, SEL, id) = (void *)imp;
func(self, s, message.body);
}
}
-(void)nativeWebView:(id)data{
NSLog(@"登录数据:%@", data);
}