fred
fred

Reputation: 157

Couldn't download from url in my app with AFNetwotking

Im noob in AFNetworking and I learning it now. I want download file from url and save in my app (Document Folder) but it dosen't work.I have one button that when click it start download.

this is my code for download file :

- (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);
    }];
}

in this code when click on button take me this massage = 'start downloads' but dont show me 'Successfully downloaded file to %@' why?? my code not complete???

Upvotes: 1

Views: 85

Answers (1)

Raptor
Raptor

Reputation: 54212

You didn't start the operation. Use the following line to start the operation :

[operation start];

Upvotes: 2

Related Questions