但是需要的是这样的
做法是这样的
延伸下(下面这个我没有验证过,但是看起来 就是对的啊)
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
你给的网页用的是 <input accept="image/*" type="file">,在IOS端点击时会提示选择图片或相机,安卓端要看浏览器对这两个属性的优化,部分浏览器会直接跳转到资源管理器,优化做得好的可以直接提示选择相册或相机。
移动设备和桌面电脑上的客户端API起初并不是同步的。最初总是移动设备上先拥有某些功能和相应的API,但慢慢的,这些API会出现在桌面电脑上。其中一个应用接口技术就是getUserMedia API,它能让应用开发者访问用户的摄像头或内置相机。