简体   繁体   English

如何在UIWebView中打开.csv链接

[英]How to open .csv link in UIWebView

I want to open .csv link in the UIWebView. 我想在UIWebView中打开.csv链接。 I am getting link some .csv links from the web how to open that link in the UIWebView. 我正在从网上获取一些.csv链接的链接,如何在UIWebView中打开该链接。 I am using the below code 我正在使用以下代码

  NSString *urlString = @"https://xoxoengage-images-test.s3.amazonaws.com/image/clients/gxoxo/annoucement/XXXXdetails201805021526899124.csv";
NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];//[NSURL URLWithString:urlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[_webviewobj loadRequest:urlRequest];

but the result is shown in the below image, help me out to sort this issue. 但结果显示在下图中,请帮助我解决此问题。 当我在webview中打开url时

The UIWebView doesn't support the CSV format natively. UIWebView本机不支持CSV格式。 See this: File Formats Supported by UIWebView 请参见: UIWebView支持的文件格式

If your server returns "text/plain" (or you have this file as ".txt") you'll see its raw text in the web view. 如果您的服务器返回“文本/纯文本”(或此文件为“ .txt”),您将在Web视图中看到其原始文本。

If you want a grid table view, then you need to convert csv to to one of the supported formats. 如果要使用网格表视图,则需要将csv转换为支持的格式之一。 The obvious choice would be HTML. 显而易见的选择是HTML。

If you can convert on the server side - that's better, otherwise download the csv file, parse it line by line, and output as HTML. 如果可以在服务器端进行转换-更好,否则请下载csv文件,逐行解析,然后输出为HTML。 Load the HTML into the web view. 将HTML加载到Web视图中。 loadHTMLString is what you could use. 您可以使用loadHTMLString

Also with UIWebView this can be done sort of transparently using a custom NSURLProtocol . 同样,使用UIWebView可以使用自定义NSURLProtocol透明地完成此操作。

This might be helpful: Where can I find a CSV to NSArray parser for Objective-C? 这可能会有所帮助: 在哪里可以找到用于Objective-C的CSV到NSArray解析器?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM