开发者

Read a .txt file from the web - Objective-C

开发者 https://www.devze.com 2023-03-17 00:50 出处:网络
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

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.som开发者_运维百科ewebsite.com/textfile.txt
else
  NSLog(@"user has no internet");

Can someone show me code to do this?


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


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


Check NSURLConnection classes.

0

精彩评论

暂无评论...
验证码 换一张
取 消