- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL * url = [request URL];
if ([[url scheme] isEqualToString:@"aaa"]) {
NSArray * SeparatedArray = [[NSArray alloc]init];
NSMutableArray *temp = [[NSMutableArray alloc] init];
SeparatedArray = [[[url absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]componentsSeparatedByString:@","];
[temp addObjectsFromArray:SeparatedArray];
NSLog(@"code1__%@:",[[url absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]);
NSLog(@"url__scheme %@",[url absoluteString]);
self.taskDownloader = [[MultiTaskDownloader alloc] init];
// taskDownloader.delegate = self;
for (int i = 0; i < SeparatedArray.count-1; i++) {
NSArray *fileNames = [[SeparatedArray objectAtIndex:i] componentsSeparatedByString:@"^"];
NSString * fileName = [fileNames lastObject];
NSLog(@"abc---%@",fileName);
[temp replaceObjectAtIndex:i withObject:fileName];
[taskDownloader addTaskUrl:[[[SeparatedArray objectAtIndex:SeparatedArray.count-1] stringByAppendingString: @"/Files/" ] stringByAppendingString:[fileName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
[taskDownloader addTaskFielName:fileName];
NSLog(@"fileName--00-%ld",(long)SeparatedArray.count);
}
[taskDownloader start];
return NO;
}
上面的是ios中的主要代码。就是拦截url。根据拦截到的内容。执行对应的判断。
function loadURL(url) {
var iFrame;
iFrame = document.createElement("iframe");
iFrame.setAttribute("src", url);
iFrame.setAttribute("style", "display:none;");
iFrame.setAttribute("height", "0px");
iFrame.setAttribute("width", "0px");
iFrame.setAttribute("frameborder", "0");
document.body.appendChild(iFrame);
// 发起请求后这个iFrame就没用了,所以把它从dom上移除掉
iFrame.parentNode.removeChild(iFrame);
iFrame = null;
}
之后就是怎么发送url了。很简单。自己看下上面的代码。想用的时候就这样:
loadURL("aaaa:"));
这样在ios那就可以拦截到aaaa了。
然后。就是你在拦截之后的想要做的东西了。
代码很简单。大家看看吧。另外,关于ios开发,建议新手多看看ios的api。一个简单的功能,不熟悉api的人就得费很大的劲去实现,而其实用api一句话就能解决。这样对api不熟悉就很容易走弯路。
更多关于ios开发的信息,可查询天地会http://ios.9tech.cn/