我是 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"];
}
Best Answer-推荐答案 strong>
喜欢@StatusReport answered与 MBHudProgress
// 1. Create `AFHTTPRequestSerializer` which will create your request.
AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
// 2. Create an `NSMutableURLRequest`.
NSMutableURLRequest *request =
[serializer multipartFormRequestWithMethod"OST" 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];
关于ios - UIPregressView 使用 AFNetWorking 上传图像,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/23864435/
|