美文网首页
关于NSURL莫名其妙为空的问题,网页打不开

关于NSURL莫名其妙为空的问题,网页打不开

作者: 不会武功的陈真 | 来源:发表于2020-01-16 13:37 被阅读0次

链接中包换中文,会导致创建NSURL对象的时候,为nil。 下面是兼容代码

//兼容一下 链接中含有中文
-(NSURL *)cz_URLWithString:(NSString *)stringURL{
    if (stringURL.length ==0) {
        return nil;
    }
    NSURL *url = [NSURL URLWithString:stringURL];
    if (!url) {
        NSString *tmpStringURL = [stringURL stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
        url = [NSURL URLWithString:tmpStringURL];
    }
    return url;
}

相关文章

网友评论

      本文标题:关于NSURL莫名其妙为空的问题,网页打不开

      本文链接:https://www.haomeiwen.com/subject/drxmactx.html