在我的iPhone应用程序中,如何从网上下载.txt文件,然后将其内容放入NSString中。例如,假设文本文件位于http://www.somewebsite.com/textfile.txt
然后我想做的是:
if(user has internet connection)
NSString *textFile = download text file from http://www.somewebsite.com/textfile.txt
else
NSLog(@"user has no internet");
有人可以告诉我代码吗?
答案 0 :(得分:2)
查看此库以通过http:http://allseeing-i.com/ASIHTTPRequest/
下载文件答案 1 :(得分:1)
要测试互联网连接,请查看Apple的Reachability
示例。它拥有您需要的所有代码。
要获取该文件,您可以查看此SO帖子:Can I make POST or GET requests from an iphone application?及其相关的后续帖子:Making GET and POST Requests from an iPhone Application - Clarification Needed
答案 2 :(得分:0)
检查NSURLConnection类。