Ios 在xcode中使用AFNetworking下载文件时出错
我创建了一个有一个页面的应用程序,在这个页面中有一个按钮,当点击时,该按钮会下载文件 我可以用AFNetworking下载文件,但在我的中有错误 这是我的代码:Ios 在xcode中使用AFNetworking下载文件时出错,ios,objective-c,download,afnetworking,Ios,Objective C,Download,Afnetworking,我创建了一个有一个页面的应用程序,在这个页面中有一个按钮,当点击时,该按钮会下载文件 我可以用AFNetworking下载文件,但在我的中有错误 这是我的代码: - (IBAction)downloads:(id)sender { NSLog(@"start downloads"); NSURLRequest *request = [NSURLRequest requestWithURL: [NSURL URLWithString: @"http://.../500x
- (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'
这是我的下载代码
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*操作”更改为“AFHTTPRequestOperation*操作”
我认为这就是问题所在使用以下行开始操作:
[operation start];
“AFURLConnectionOperation*操作”将此更改为“AFHTTPRequestOperation*操作”我的朋友更正了它,但我不从url下载文件!!!为什么?你的意思是仍然没有下载?检查你的url,复制粘贴到浏览器中,并检查它是否工作