Загрузка изображения UIPregressView с помощью AFNetWorking

Я новичок в разработке iOS. Я создаю метод загрузки изображения с помощью «AFNetworking». И я хочу добавить UIProgressView при обработке.

Теперь я использую «DejalBezelActivityView» в своем методе загрузки. «DejalBezelActivityView» работает, но я хочу использовать UIProgressView.

Как это сделать?

Это пример моего кода:

-(void) uploadImage
{
    // Set Data to Web API   
    // NSMutableArray *newPictureData = ...

    // WEB API
    [PictureClient uploadPictures:newPictureData whenCompleted:^(BOOL success, NSString *data, NSError *error)
    {
         if (success)
         {
              [DejalBezelActivityView removeViewAnimated:YES];
               UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@“Complete"
                                                                     message:@“Upload Cpmplete"
                                                                    delegate:self
                                                           cancelButtonTitle:@"OK"
                                                           otherButtonTitles:nil];
              [myAlertView show];

              // Do somethings
              // ...
         }
         else
         {
              [DejalBezelActivityView removeViewAnimated:YES];

              // Error                 
              UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@“Error"
                                                              message:errorCode
                                                             delegate:self
                                                    cancelButtonTitle:@"OK"
                                                    otherButtonTitles:nil];
              [alert show];                  
        }
    }];

    [DejalBezelActivityView activityViewForView:self.view withLabel:@“During Picture"];
}

person Natthawat Sudsang    schedule 26.05.2014    source источник


Ответы (1)


например, @StatusReport ответил с помощью MBHudProgress

// 1. Create `AFHTTPRequestSerializer` which will create your request.
AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];

// 2. Create an `NSMutableURLRequest`.
NSMutableURLRequest *request =
    [serializer multipartFormRequestWithMethod:@"POST" URLString:@"http://www.myurl.com"
                                    parameters:dataToPost
                     constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
                       [formData appendPartWithFileData:imageData
                                                   name:@"attachment"
                                               fileName:@"myimage.jpg"
                                               mimeType:@"image/jpeg"];
                     }];

// 3. Create and use `AFHTTPRequestOperationManager` to create an `AFHTTPRequestOperation` from the `NSMutableURLRequest` that we just created.
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
AFHTTPRequestOperation *operation =
    [manager HTTPRequestOperationWithRequest:request
                                     success:^(AFHTTPRequestOperation *operation, id responseObject) {
                                       [MBProgressHUD hideHUDForView:self.view animated:YES];
                                       NSLog(@"Success %@", responseObject);
                                     } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                       [MBProgressHUD hideHUDForView:self.view animated:YES];
                                       NSLog(@"Failure %@", error.description);
                                     }];

// 4. Set the progress block of the operation.
[operation setUploadProgressBlock:^(NSUInteger __unused bytesWritten,
                                    long long totalBytesWritten,
                                    long long totalBytesExpectedToWrite) {
  NSLog(@"Wrote %lld/%lld", totalBytesWritten, totalBytesExpectedToWrite);

}];

// 5. Begin!
[operation start];
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
person Tomer Even    schedule 26.05.2014