objective-c - 如何使用 NSURL 下载

标签 objective-c iphone cocoa-touch nsurlconnection

- (IBAction)startDownloadingURL:(id)sender
{
    // create the request
    NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com/index.html"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];

    // create the connection with the request
    // and start loading the data
    NSURLDownload  *theDownload=[[NSURLDownload alloc] initWithRequest:theRequest delegate:self];

    if (!theDownload) {
        // inform the user that the download could not be made
    }
}

当我运行模拟器时,出现错误:

NSURLDownload undeclared, first use in this function.

在哪里导入NSURLDownload的库

最佳答案

NSURLDownload not on iPhone见注释:

iPhone OS Note: The NSURLDownload class is not available in iPhone OS as downloading directly to the file system is discouraged. Use the NSURLConnection class instead. See “Using NSURLConnection” for more information.

查看 Apple 关于 URL loading system 的文档和 NSURLDownload .

关于objective-c - 如何使用 NSURL 下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2497149/

相关文章:

objective-c - Xcode/Cocoapods 为什么我不能从 Pod 实现 Swift 协议(protocol)?

objective-c - 将非拥有的窗口设置为始终在顶部 - 就像应用程序 "Afloat"

ios - 如果在重新加载 UiTableView 时 View 消失,应用程序会崩溃

iphone - 从 NSData 或 UIImage 查找图像类型

iphone - 文件的所有者未显示选项卡栏 Controller socket ?

objective-c - Xcode 中针对 Objective-C 的类似 JavaDoc 的文档?

iphone - objective-c:将变量初始化为 nil

ios - Swift:Parse 中的长查询(OR/AND 条件)

ios - 如何像iOS Music App TableView一样将UITableView分为三部分?

iphone - 在我的 iPhone 应用程序中读取 "Settings"应用程序数据