我是 AFNetworking 的菜鸟,我现在正在学习它。我想从 url 下载文件并保存在我的应用程序(文档文件夹)中,但它不起作用。我有一个按钮,当点击它开始下载时。
这是我的下载文件代码:
- (IBAction)downloads:(id)sender
{
NSLog(@"start downloads");
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://192.168.1.100/mamal/filemanager.php"]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [paths objectAtIndex:0];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:[path stringByAppendingPathComponent:@"filemanager.php"] append:NO];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Successfully downloaded file to %@", path);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}
在此代码中,当单击按钮时带我按摩 = '开始下载',但不显示'成功下载文件到 %@' 为什么?我的代码不完整???