0

I want to open .csv link in the UIWebView. I am getting link some .csv links from the web how to open that link in the 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.when i open url in webview

Gaurav Patel
  • 532
  • 1
  • 5
  • 19

1 Answers1

0

The UIWebView doesn't support the CSV format natively. See this: File Formats Supported by UIWebView

If your server returns "text/plain" (or you have this file as ".txt") you'll see its raw text in the web view.

If you want a grid table view, then you need to convert csv to to one of the supported formats. The obvious choice would be 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. Load the HTML into the web view. loadHTMLString is what you could use.

Also with UIWebView this can be done sort of transparently using a custom NSURLProtocol.

This might be helpful: Where can I find a CSV to NSArray parser for Objective-C?

battlmonstr
  • 5,841
  • 1
  • 23
  • 33