UIWebView加载txt格式文件乱码问题解决

if([path hasSuffix:@".txt"]){
        NSString *body = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
        if(!body){

    //gb2312编码后再尝试打开
            NSStringEncoding enc =CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
            body = [NSString stringWithContentsOfURL:url encoding:enc error:nil];
        }
        if(body){
            [WS_WebDocumentView loadHTMLString:body baseURL:nil];
        }else{
            [WS_WebDocumentView loadRequest:request];
        }
    }

转载于:https://www.cnblogs.com/ThankForYou/archive/2012/07/04/2575939.html

你可能感兴趣的:(UIWebView加载txt格式文件乱码问题解决)