您现在的位置是:主页 > news > 网站首页弹出公告模板/指数函数和对数函数

网站首页弹出公告模板/指数函数和对数函数

admin2025/6/25 8:30:10news

简介网站首页弹出公告模板,指数函数和对数函数,大连网站建设方案维护,大联盟平台推广我是较新的 AFNetworking 2.0。使用下面的代码片段,我已经能够成功地将一张照片上传到我的 url。我想要跟踪的增量上载进度,但我找不到这样做 2.0 版的示例。我的应用程序是 iOS 7,所以我已经选择了为 AFHTTPSessionManager。 任何人都可以提…

网站首页弹出公告模板,指数函数和对数函数,大连网站建设方案维护,大联盟平台推广我是较新的 AFNetworking 2.0。使用下面的代码片段,我已经能够成功地将一张照片上传到我的 url。我想要跟踪的增量上载进度,但我找不到这样做 2.0 版的示例。我的应用程序是 iOS 7,所以我已经选择了为 AFHTTPSessionManager。 任何人都可以提…

我是较新的 AFNetworking 2.0。使用下面的代码片段,我已经能够成功地将一张照片上传到我的 url。我想要跟踪的增量上载进度,但我找不到这样做 2.0 版的示例。我的应用程序是 iOS 7,所以我已经选择了为 AFHTTPSessionManager。

任何人都可以提供如何修改这段上传进度进行跟踪的示例?

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"myimage.jpg"], 1.0);[manager POST:@"http://myurl.com" parameters:dataToPost constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {[formData appendPartWithFileData:imageData name:@"attachment" fileName:@"myimage.jpg" mimeType:@"image/jpeg"];
} success:^(NSURLSessionDataTask *task, id responseObject) {NSLog(@"Success %@", responseObject);
} failure:^(NSURLSessionDataTask *task, NSError *error) {NSLog(@"Failure %@, %@", error, [task.response description]);
}];

解决方法 1:

接口的 AFHTTPSession 不能提供一种方法来设置进度块。相反,必须进行以下操作:

// 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:dataToPostconstructingBodyWithBlock:^(id<AFMultipartFormData> formData) {[formData appendPartWithFileData:imageDataname:@"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:requestsuccess:^(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!
[operation start];

此外,你不需要读取图像通过 UIImage ,然后压缩它再次使用 JPEG 获得 NSData 。只是使用 +[NSData dataWithContentsOfFile:] ,从您捆绑直接读取该文件。

转载于:https://www.cnblogs.com/melons/p/5791991.html