Comments (7)
嗯,你这个我要先测试下
from kkjsbridge.
你好,我不太清楚,你是需要ajax请求一个本地资源吗,这是什么样的场景?
from kkjsbridge.
你好,我不太清楚,你是需要ajax请求一个本地资源吗,这是什么样的场景?
我这边的场景是浏览器加载网页,网页可能是本地地址,也可能是网络地址;然后就遇到下面这两种情况,目前你的代码满足不了,所以我做了调整。上次的代码有缺陷,这次又做了一些调整;
NSURL *nativeURL = [NSURL URLWithString:url];
if (!nativeURL.scheme) {
/*------------兼容的代码 start------------*/
// 说明是相对路径,一般是资源文件
// 示例1
// {
// async = 1;
// host = "m.feng1.com";
// href = "https://m.feng1.com/mall/app/index.html?channel=xxx&ddsds=ewew2222";
// id = 632;
// method = GET;
// port = "";
// referer = "";
// scheme = "https:";
// url = "/api/mall/channelConfig/getChannelThemeConfig?channel=SFIM&_=1578133077103";
// useragent = "Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16A366";
// }
//
// 示例2
// {
// async = 1;
// host = "";
// href = "file:///Users/xxxx/Library/Developer/CoreSimulator/Devices/B9133CAF-51E9-456E-92F6-FAC6EFC676AB/data/Containers/Data/Application/5BCBB3E7-A35F-4BCD-89B7-A79474C0E2C8/Documents/c6a5a31f3f1d9e446353e0425ab55c3e/2e6cda38b47d8c6ec672a1ed4f66cfe8/b8c37e33defde51cf91e1e03e51657da/UnityFile/Cache/serviceApp/packages/salary/f99bb68cfd2680c098a287fca1182030/www/index.html#/dsdsds/ddd?key=xxx&eewwe";
// id = 496;
// method = GET;
// port = "";
// referer = "";
// scheme = "file:";
// url = "views/salaryInquiry/ssf-account-edit.html";
// useragent = "Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16A366";
// }
// 先按照?截取,然后按照#截取
NSString* path = [href componentsSeparatedByString:@"?"][0]; // 按“?”进行分割,获取第一个字符串
path = [path componentsSeparatedByString:@"#"][0]; // 按“#”进行分割,获取第一个字符串
path = [path stringByDeletingLastPathComponent]; // 删除最后一个“/”之后的内容,获取到当前文件的相对路径
if ([scheme hasPrefix:@"file:"]) {
// 本地相对路径
if (![url hasPrefix:@"/"]){
path = [NSString stringWithFormat:@"%@/",path];
}
// 完整路径
url = [NSString stringWithFormat:@"%@%@",path,url];
}else{
// 网络相对路径
if (![url hasPrefix:@"/"]){
url = [NSString stringWithFormat:@"%@%@",path,url];
}else {
// 网络路径,拼接host
NSString *tmpPort = port.length > 0 ? [NSString stringWithFormat:@":%@", port] : @"";
url = [NSString stringWithFormat:@"%@//%@%@%@",scheme, host, tmpPort, url];
}
}
/*-----------兼容的代码 end-------------*/
/*-----------下面是你原来的代码--------*/
// NSFileManager* fm = [NSFileManager defaultManager];
//
// if (nativeURL.pathComponents > 0) {
// if (nativeURL.host) {
// url = [NSString stringWithFormat:@"%@%@",scheme, url];
// } else {
// NSString *tmpPath = [url hasPrefix:@"/"] ? url : [NSString stringWithFormat:@"/%@", url];
// NSString *tmpPort = port.length > 0 ? [NSString stringWithFormat:@":%@", port] : @"";
// url = [NSString stringWithFormat:@"%@//%@%@%@",scheme, host, tmpPort, tmpPath];
// }
// } else {
// url = href;
// }
}
from kkjsbridge.
嗯,你提一个PR吧
from kkjsbridge.
嗯,你提一个PR吧
已经提交,请查收。顺带提交了一些其他的内容
from kkjsbridge.
嗯,好的,不好意思,这么久才回复。我review了下,你的提交,也给了下建议,你看看呢。
from kkjsbridge.
现在没有路径问题了
from kkjsbridge.
Related Issues (20)
- window.prompt("KKJSBridge", messageString)不触发UIDelegate回调方法 HOT 4
- url参数包含中文,利用 requestId 生成新的 url就会有问题 HOT 5
- 如何实现重定向页面的跳转 HOT 4
- 用了这个解决了ajax请求body丢失的问题后又出现xhr.upload.addeventlistener 失效的问题 HOT 1
- cookie问题请教 HOT 2
- H5离线包如果使用虚拟域名加载可以支持吗? HOT 1
- 使用测试Demo加载百度,打开百度新闻视频类加载不了
- 302 重定向后 cookie 出错
- Demoy源码
- crash:NSOperationQueue 0x282bedca0 (QOS: UNSPECIFIED) HOT 1
- ajax同步请求这里为啥直接弹alert了大佬
- 如果是使用Ajax Hook 部分 API + NSURLProtocol会不会app store审核能过吗? HOT 1
- 复用时,H5 跳转页面,点导航返回异常 HOT 1
- iframe 的请求,body 是空的
- websocket拦截不了
- -[__NSArrayM bytes]: unrecognized selector sent to instance
- Google CapTcha HOT 1
- Hook后无法正常打开网页 HOT 1
- 使用KKWebView后js交互方法执行异常
- 在 iOS14.x 版本中出现了 localstorage 不同步的问题
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kkjsbridge.