weex框架源码中有个类WXURLRewriteDefaultImpl,该类中有个方法对URLString字符串的处理欠妥当,方法和更改方式见如下注释:
- (NSURL *)rewriteURL:(NSString *)url
withResourceType:(WXResourceType)resourceType
withInstance:(WXSDKInstance *)instance
{
// url 需要先进行一次 NSUTF8 转码,否则,如果url里面有中文,得到的completeURL为nil,导致带中文的图片网址加载不出来
NSString *UTF8URLString = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *completeURL = [NSURL URLWithString:UTF8URLString];
if ([completeURL isFileURL]) {
return completeURL;
} else if ([self isLocalURL:completeURL]) {
NSString *resourceName = [[completeURL host] stringByAppendingString:[completeURL path]];
NSURL *resourceURL = [[NSBundle mainBundle] URLForResource:resourceName withExtension:@""];
if (!resourceURL) {
WXLogError(@"Invalid local resource URL:%@, no resouce found.", url);
}
return resourceURL;
} else {
// 这里改为传转码后的url
return [instance completeURL:UTF8URLString];
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…