Ios我可以从Graph api Facebook获得上传进度吗?

时间:2015-01-29 10:30:48

标签: ios iphone facebook facebook-graph-api

在我的应用中,我需要将视频上传到用户的脸书墙。我使用这段代码并且有效:

[FBRequestConnection startWithGraphPath:@"me/videos"
                             parameters:params
                             HTTPMethod:@"POST"
                      completionHandler:^(FBRequestConnection *connection,
                                          id result,
                                          NSError *error)
 {
     if (error)
     {
         //showing an alert for failure

     }
     else
     {
         //showing an alert for success



     }

 }];

我想在上传时添加一个进度条......但是我找不到任何有用的东西......我也读过文档,但我找不到任何东西......那里是一种管理@" me / videos"的进度条的方法。 ?

1 个答案:

答案 0 :(得分:0)

您可以在FBRequestConnection上设置FBRequestConnectionDelegate,请参阅https://developers.facebook.com/docs/reference/ios/current/protocol/FBRequestConnectionDelegate/,并实现requestConnection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite方法。

您的进度应为totalBytesWritten / totalBytesExpectedToWrite。

如果要设置委托,还需要单独创建FBRequest和FBRequestConnection,如:

FBRequest *request = [FBRequest requestForUploadVideo:@"some_path"];
FBRequestConnection *connection = [[FBRequestConnection alloc] init];
[connection addRequest:request completionHandler:YOUR_HANDLER_HERE];
connection.delegate = self;
[connection start];