iOS html 本地加载附加传参数

2022-04-06  本文已影响0人  Jesscia_Liu

//获取本地网页路径
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"html"];

//传参数:
NSString *urlStr = filePath;
urlStr = [urlStr stringByAppendingString:[NSString stringWithFormat:@"?id=%@", idNum]];

urlStr = [urlStr stringByAppendingString:[NSString stringWithFormat:@"&name=%@", name]];
    
//转换url
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"file://%@",[urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]]];
NSURLRequest *request =[NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:15];

//加载本地网页
[self.webView loadRequest:request];
上一篇 下一篇

猜你喜欢

热点阅读