如何查看我的Facebook iOS上传进度? [英] How can I check the progress of my Facebook iOS upload?

查看:191
本文介绍了如何查看我的Facebook iOS上传进度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Facebook iOS SDK,并使用Graph API将视频上传到Facebook.

I'm using the Facebook iOS SDK and using the Graph API to upload videos to Facebook.

上传工作正常,但是我可以跟踪上传进度,以便在进度栏中反映进度.

The uploading is working perfectly fine, but can I keep track of the progress of the upload so I can reflect the progress in a progress bar.

推荐答案

这是一个古老的问题,但是最新的Facebook iOS SDK v3.9可以实现您想做的事情. (2013年10月27日)

This is an old question but what you're trying to do is possible with latest Facebook iOS SDK v3.9. (27 Oct 2013)

本质上,FBRequestConnection公开了一个urlRequest(NSMutableURLRequest)属性,您可以使用该属性向其他任何第三方联网框架甚至Apple提供的框架发送数据.

Essentially, FBRequestConnection exposes a property urlRequest (NSMutableURLRequest) that you can use to send out the data any other third party networking frameworks or even the ones Apple provided.

https://developers.facebook.com/docs/reference/ios/current /class/FBRequestConnection#urlRequest

这是一个示例,说明如何使用AFNetworking 1.x获取进度回调.

Here's an example how I get progress callbacks using AFNetworking 1.x.

NSDictionary *parameters = @{ @"video.mov": videoData,
                              @"title": @"Upload Title",
                              @"description": @"Upload Description" };

创建FBRequest

FBRequest *request = [FBRequest requestWithGraphPath:@"me/videos" 
                                          parameters:parameters
                                          HTTPMethod:@"POST"];

生成FBRequestConnection(取消并提取URLRequest)

FBRequestConnection *requestConnection = [request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
}];
[requestConnection cancel];

NSMutableURLRequest *urlRequest = requestConnection.urlRequest;

使用AFNetworking HTTPRequestOperation

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:urlRequest];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
  // Do your success callback.
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
  // Do your failure callback.
}];

设置进度回调

[operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
  NSLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite);
}];

开始操作

[[APIClient sharedInstance] enqueueHTTPRequestOperation:operation];
// APIClient is a singleton class for AFHTTPClient subclass

这篇关于如何查看我的Facebook iOS上传进度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆