首页 > 代码库 > h5 与app交互
h5 与app交互
<style></style>
JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"]; JSTextObject * jsiOSObject = [JSTextObject new]; context[@"jsTextObject"] = jsiOSObject; NSString *jsStr1=@"jsTextObject.CalliOSFunction()"; JSValue *value1 = [context evaluateScript:jsStr1]; DDLogInfo(@"the value 1 is %@", value1); NSString *jsStr2=@"jsTextObject.CalliOSFunctionParamter(‘hello‘)"; JSValue *value2 = [context evaluateScript:jsStr2]; DDLogInfo(@"the value 1 is %@", value2); context[@"test1"] = ^() { NSArray *args = [JSContext currentArguments]; for (id obj in args) { NSLog(@"test1 %@",obj); } }; context[@"share"] = ^() { NSLog(@"+++++++Begin Log+++++++"); NSArray *args = [JSContext currentArguments]; // dispatch_async(dispatch_get_main_queue(), ^{// UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"方式二" message:@"这是OC原生的弹出窗" delegate:self cancelButtonTitle:@"收到" otherButtonTitles:nil];// [alertView show];// }); NSString *title = @""; for (JSValue *jsVal in args) { if ([title isEqualToString:@""]) { title = jsVal.toString; } NSLog(@"%@", jsVal.toString); } dispatch_async(dispatch_get_main_queue(), ^{ UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"方式二" message:title delegate:self cancelButtonTitle:@"收到" otherButtonTitles:nil]; [alertView show]; }); NSLog(@"-------End Log-------"); };
h5 与app交互
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。