该字符串约500个字符,需要在应用启动时下载。
最佳答案
如果速度不是关键,你可以简单地写:
NSString *string = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://example.com/str.txt"]];
但是,如果你想要优雅、惯用和安全(如果上面的代码超时,iOS 会杀死你的应用程序!),使用 NSURLConnection,或者简单地将上面的代码包装到 NSThread 中。
NSURLConnection 文档: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.html
希望对您有所帮助。
关于iphone - 在 Cocoa-Touch 中从 URL 下载数据的最简单方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8958119/