js调用ios
❶ js调用ios方法 bridge.callHandler 里面的回调函数不执行
bridge.callHandler 前添加代码
if(如果是android){
try { bridge.init(function (message, responseCallback) { }); } catch (e) { }
}
方法已经给你了,作为回报我内想知道为啥容
❷ ios js交互怎么调用udid
UDID可以看作为苹果设备的身份证号 NSString *uuid = [[UIDevice currentDevice] uniqueIdentifier];获取设备的udid
❸ JS实现怎么唤起IOS的下载提示
这个可以压缩后再跳转
比如将文件压缩为zip,然后通过js
location.href = './a.zip';
就可以下载
一般的txt、php、html文件等都会被ios的safari正常当文本输出
❹ 如何实现网页代码(JS/HTML)和IOS应用程序交互
//①ji与android交互
//js调用android方法
window.类.方法名称(参数1,参数2);
//android调用js方法(loginIn:方法名称,uname:参数)
//activity.loadUrl("javascript:loginIn('"+uname+"');");
//②js与ios交互
//js调用ios方法(objc:协议)
window.location.href='objc://方法名称|参数1|参数2';
//ios调用js方法:
同android
其中:android的activity如下:
@Override
publicvoidonCreate(BundlesavedInstanceState){
//setFullScreen(true);
Intentintent=newIntent(getApplicationContext(),
SplashActivity.class);
startActivity(intent);
super.onCreate(savedInstanceState);
super.init();
//Setby<contentsrc="index.html"/>inconfig.xml
activity=this;
//this.appView.setBackgroundResource(R.drawable.welcome);//设置背景图片
//
//super.setIntegerProperty("splashscreen",R.drawable.welcome);
//设置闪屏背景图片
//super.setBooleanProperty(name,value)
//super.loadUrl("这里是html页面的路径");
super.appView.addJavascriptInterface(newFu(),"这里是类名(js中需要通过这个类名访问android方法)");
super.loadUrl(Config.getStartUrl());
//super.loadUrl("file:///android_asset/www/index.html")
//mController.openShare(activity,false);
//try{
//getToken();
//}catch(NoSuchAlgorithmExceptione){
////TODOAuto-generatedcatchblock
////e.printStackTrace();
//}
}
❺ 如何用js调用ios
基本流程:
先看一下Web中,我们给h1标签添加一个onclick事件,让它在被点击之后,修改当前的url。
Web中的HTML代码:
<html>
<head>
<script>
function getInfo(name)
{
window.location = "/getInfo/"+name;
}
</script>
</head>
<body>
<h1 onclick="getInfo('why')">Name</h1>
</body>
</html>
iOS中,先拖拽WebView,访问localhost,然后通过WebView的委托事件监听url跳转操作,并且把跳转截取下来。
也就是说,在onclick的时候,普通浏览器灰跳转到那个url,但是在iOS的这个WebView里面,这个跳转会被拦截,
用这种方式可以巧妙地实现JS调用iOS的原生代码:
//
// DWViewController.m
// DareWayApp
//
// Created by why on 14-6-3.
// Copyright (c) 2014年 DareWay. All rights reserved.
//
#import "DWViewController.h"
@interface DWViewController ()
@property (weak, nonatomic) IBOutlet UIWebView *myWebview; // 主页面
@end
@implementation DWViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// 适配iOS6的状态栏
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
_myWebview.frame = CGRectMake(0,20,self.view.frame.size.width,self.view.frame.size.height-20);
}
// 加载制定的URL
NSURL *url =[NSURL URLWithString:@"http://localhost"];
NSURLRequest *request =[NSURLRequest requestWithURL:url];
[_myWebview setDelegate:self];
[_myWebview loadRequest:request];
}
// 网页中的每一个请求都会被触发
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
// 每次跳转时候判断URL
if([request.mainDocumentURL.relativePath isEqualToString:@"/getInfo/why"])
{
NSLog(@"why");
return NO;
}
return YES;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end