Reputation: 5137
In my iPhone app, how can I download a .txt file from the web, and then get it's contents into an NSString. For instance, say the text file was located at http://www.somewebsite.com/textfile.txt
Then what I want to do is:
if(user has internet connection)
NSString *textFile = download text file from http://www.somewebsite.com/textfile.txt
else
NSLog(@"user has no internet");
Can someone show me code to do this?
Upvotes: 4
Views: 1537
Reputation: 48398
To test for internet connectivity, look at Apple's Reachability
example. It has all the code you'll need for that.
To get the file, you may want to check out this SO post: Can I make POST or GET requests from an iphone application? and its relevant follow-up post: Making GET and POST Requests from an iPhone Application - Clarification Needed
Upvotes: 1
Reputation: 1101
Check out this library to download files via http: http://allseeing-i.com/ASIHTTPRequest/
Upvotes: 2