Read .txt file from the Internet - Objective-C

In my iPhone application, how can I download a .txt file from the Internet and then get its contents in NSString. For example, let's say the text file was at http://www.somewebsite.com/textfile.txt

Then I want to do the following:

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 the code for this?

+4
source share
3 answers

Check out this library to download files via http: http://allseeing-i.com/ASIHTTPRequest/

+2
source

To check your internet connection, check out the Apple Reachability example. It has all the code you need for this.

To get the file you can check this post SO: Can I make POST or GET requests from iphone application? and its corresponding follow-up post: Performing GET and POST requests from an iPhone application - Clarification required

+1
source

Check out the NSURLConnection classes.

0
source

All Articles