混合开发笔记 发表于 2016-03-17 | 分类于 编程 | h5和android的混合开发(前端代码):12345678910111213141516171819202122232425262728<script type="text/javascript">// console.log("我是token:"+req.session.accessToken)// var accessToken="15242ed7d2a359547fb286f5b5cb44274470060b6c694399b023893cb6cbb762d11ca0c3ccfb49f4b03e857389b40da7d333fa48d7f3b8cbc6afee53d707220d"; var jsonObject={ "userInfo": { "id": "9", "accessToken": "15242ed7d2a359547fb286f5b5cb44274470060b6c694399b023893cb6cbb762d11ca0c3ccfb49f4b03e857389b40da7d333fa48d7f3b8cbc6afee53d707220d" }}; function syncLogin(jsonObject){ /*app native未登录,H5端登录后同步userInfo到native实现自动登录 */ if("JsBridge" in window){// JsBridge.toast('测试一下而已') JsBridge.syncLogin(jsonObject); } } syncLogin(jsonObject); function checkNativeLogin(){ JsBridge.checkNativeLogin();// var userInfo=JSON.parse(JsBridge.checkNativeLogin()); var userInfo=JsBridge.checkNativeLogin();// JsBridge.toast(userInfo.userInfo.userId);// JsBridge.toast(userInfo.userInfo.userId); } checkNativeLogin();</script> h5和object-c的混合开发(前端代码):1234567891011121314151617181920<html> <head> <meta http-equiv="content-type"content="text/html;charset=utf-8"> <title>js调用oc</title> <script type="text/javaScript"> /* 调用本地带参数的方法 */ function testFunction1(cmd,parameter1){ return document.location="objc://"+cmd+":/"+parameter1; //cmd代表objective-c中的的方法名,parameter1自然就是参数了 } /* 调用本地不带参数的方法 */ function testFunction2(cmd){ return document.location="objc://"+cmd; //cmd代表objective-c中的的方法名 } </script> </head> <body> <p><button type="text" id="text1" value="点击这里1"onclick="testFunction1('printLog:','str')">调用本地带参数的方法</button></p> <p><button type="text" id="text2" value="点击这里2"onclick="testFunction2('testFunc')">调用本地不带参数的方法</button></p> </body> </html>