0

我创建了一个具有一页的应用程序,并且在此页面中存在一个单击时下载文件的按钮。

我可以使用 AFNetworking 下载文件,但出现错误....

这是我的代码:

- (IBAction)downloads:(id)sender
{
    NSLog(@"start downloads");
    NSURLRequest *request = [NSURLRequest requestWithURL:
   [NSURL URLWithString:
   @"http://.../500x333xgalaxy-core-product-image-1tn.jpg,
                           q1367836642.pagespeed.ic.eafBYU8jUN.jpg"]];
    AFURLConnectionOperation *operation = [[AFHTTPRequestOperation alloc]
                                                             initWithRequest:request];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
                                                                   NSUserDomainMask, YES);
    NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent
                                                                        :@"filename.jpg"];

    operation.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO];

    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, 
    id responseObject) {
        NSLog(@"Successfully downloaded file to %@", path);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Error: %@", error);
    }];

}

在此处输入图像描述

这个错误是:

No visible @interface 'AFURLConnectionOpretion' declares the selector
                                                         'setCompletionBlockWithSuccess'
4

2 回答 2

0

这是我的下载代码

AFHTTPRequestOperation *urlConnection;
urlConnection = [[AFHTTPRequestOperation alloc] initWithRequest:request];
urlConnection.outputStream = [NSOutputStream outputStreamToFileAtPath:outputPath append:NO];
[urlConnection setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

    NSLog(@"Download Completed");


} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

    NSLog(@"Error occured while downloading");

}];

[urlConnection setDownloadProgressBlock:^(NSInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {

}];

将“AFURLConnectionOperation * operation”更改为“AFHTTPRequestOperation * operation”我认为这就是问题所在

于 2013-05-06T13:18:02.407 回答
0

使用以下行开始操作:

[operation start];
于 2013-05-08T09:28:47.543 回答