Download file using AFNetworking on iOS 6

后端 未结 3 981
[愿得一人]
[愿得一人] 2021-01-15 15:51

I\'ve recently updated to AFNetworking 2.0. The documentation said it is compatible with iOS6.0+. I am building a iOS 6.0 app, when I am trying to implement a download metho

3条回答
  •  感动是毒
    2021-01-15 16:07

    try this...

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    AFHTTPRequestOperation *operation = [manager GET:urlString
                                          parameters:nil
                                             success:^(AFHTTPRequestOperation *operation, NSData *responseData)
                                         {
                                             [responseData writeToURL:someLocalURL atomically:YES];
                                         }
                                             failure:^(AFHTTPRequestOperation *operation, NSError *error)
                                         {
                                             NSLog(@"Downloading error: %@", error);
                                         }];
    
    [operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead)
     {
         float downloadPercentage = (float)totalBytesRead/(float)(totalBytesExpectedToRead);
    
         [someProgressView setProgress:downloadPercentage animated:YES];
     }];
    

提交回复
热议问题