ios - UIPregressView 使用 AFNetWorking 上传图像
<p><p>我是 iOS 开发的新手。我使用“AFNetworking”创建上传图像方法。我想在处理时添加 <code>UIProgressView</code>。</p>
<p>现在我在上传方法中使用“DejalBezelActivityView”
“DejalBezelActivityView”工作,但我想使用 <code>UIProgressView</code>。</p>
<p>怎么做?</p>
<p>这是我的代码示例:</p>
<pre><code>-(void) uploadImage
{
// Set Data to Web API
// NSMutableArray *newPictureData = ...
// WEB API
[PictureClient uploadPictures:newPictureData whenCompleted:^(BOOL success, NSString *data, NSError *error)
{
if (success)
{
;
UIAlertView *myAlertView = [ initWithTitle:@“Complete"
message:@“Upload Cpmplete"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
;
// Do somethings
// ...
}
else
{
;
// Error
UIAlertView *alert = [ initWithTitle:@“Error"
message:errorCode
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
;
}
}];
;
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>喜欢@StatusReport <a href="https://stackoverflow.com/a/20543730/810466" rel="noreferrer noopener nofollow">answered</a>与 <a href="https://github.com/jdg/MBProgressHUD#usage" rel="noreferrer noopener nofollow">MBHudProgress</a> </p>
<pre><code>// 1. Create `AFHTTPRequestSerializer` which will create your request.
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 = ;
AFHTTPRequestOperation *operation =
[manager HTTPRequestOperationWithRequest:request
success:^(AFHTTPRequestOperation *operation, id responseObject) {
;
NSLog(@"Success %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
;
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!
;
;
</code></pre></p>
<p style="font-size: 20px;">关于ios - UIPregressView 使用 AFNetWorking 上传图像,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/23864435/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/23864435/
</a>
</p>
页:
[1]