h5 与app交互
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了h5 与app交互相关的知识,希望对你有一定的参考价值。
JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javascriptContext"]; JSTextObject * jsiosObject = [JSTextObject new]; context[@"jsTextObject"] = jsiOSObject; NSString *[email protected]"jsTextObject.CalliOSFunction()"; JSValue *value1 = [context evaluateScript:jsStr1]; DDLogInfo(@"the value 1 is %@", value1); NSString *[email protected]"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交互的主要内容,如果未能解决你的问题,请参考以下文章