0

I'm aware that there are similar questions posted, but this is a very specific issue that may or may not be related to code, it might be due to where I'm sourcing the file, and I need some advice.

I have an iPad app and am detecting whether there is an internet connection. If there is, then a .csv file is downloaded, saved, then split into an array. If not then a file held in the main bundle is used.

When using the file held in the main bundle, I can extract the data. The problem I have is when I try to download the .csv. The file is held on Document Manager, a Content Management System that is the only secure area for the file to be held for the company I work for and is therefore unavoidable. If I use this code:

NSString *urlString = @".../view-document.cgi?f=fundsspreadsheetc.csv";

(sorry, I need to keep the full link confidential)

NSURL *csvURL = [NSURL URLWithString:[urlString stringByAddingPercentageEscapesUsingEncoding:NSASCIIStringEncoding]];

NSData *urlData = [NSData dataWithContentsOfURL:csvURL options:NSDataReadingMappedAlways error:nil];

then urlData returns nil.

The original url opens the file on a windows laptop, but with a file name of view-document.cgi. I don't know if this is relevant.

If I change the url to: "

http://download.finance.yahoo.com/d/quotes.csv?s=^GSPC+^IXIC+^dji+^GSPC+^BVSP+^GSPTSE+^FTSE+^GDAXI+^FCHI+^STOXX50E+^AEX+^IBEX+^SSMI+^N225+^AXJO+^HSI+^NSEI&f=sl1d1t1c1ohgv&e=.csv"

from a question set by shebi, then my code works.

What do I need to do to get my file to download?

much appreciated

Community
  • 1
  • 1
user2903240
  • 105
  • 1
  • 1
  • 5
  • If it works on a normal downloaded file, then it seems like something in your full link stops it from downloading. Do you need certain login credentials to access the file? If you load your full urlString into a browser, does it download the file to your machine? – Owen Hartnett Apr 22 '14 at 15:22
  • 1
    Try using `NSURL *csvURL = [NSURL URLWithString:urlString];` – rmaddy Apr 22 '14 at 15:22
  • 1
    The method you're using to download the file has an error parameter. You should use it rather than setting it to nil. It will help you diagnose the problem. – rdelmar Apr 22 '14 at 15:26
  • rmaddy, that didn't work but thanks. – user2903240 Apr 22 '14 at 15:57
  • I don't need to log in and the full link is: http://www.aviva.co.uk/adviser/product-literature/view-document.cgi?f=fundsspreadsheetc.csv – user2903240 Apr 22 '14 at 15:58
  • When I try to access that link I get 404 errors, looking at the error parameter might very well give you more information. Something else to try is run it in the simulator and use something like wireshark to monitor the network traffic. – David Berry Apr 22 '14 at 16:04

1 Answers1

0

Thanks for the help, it was problem with the link.

user2903240
  • 105
  • 1
  • 1
  • 5