Facebook iPhone SDK: show a progress bar while upl

2019-05-10 23:57发布

I want to show a progress bar while my iPhone app is uploading an image to Facebook. Is it possible?

Can I do it with every FBRequest that I make? I also use FBRequest to check extended permission and sometimes takes a lot of time.

Thank you.

2条回答
虎瘦雄心在
2楼-- · 2019-05-11 00:32

For the progress bar there is a little hack you can do. In the FBRequest.h file add this line in the FBRequestDelegate protocol:

- (void)request:(FBRequest *)request didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite;

After that in the FBRequest.m file add this function:

- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite {
    if ([_delegate respondsToSelector:@selector(request:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:)]) {
        [_delegate request:self didSendBodyData:bytesWritten totalBytesWritten:totalBytesWritten totalBytesExpectedToWrite:totalBytesExpectedToWrite];
    }
}

Now your delegate will receive a message every time more data it's posted to the server. So basically if you implement this into your delegate you should see some activity in your log:

- (void)request:(FBRequest *)request didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite
{
    NSLog(@"%d bytes out of %d sent.", totalBytesWritten, totalBytesExpectedToWrite);
}

Let me know if you have any problems hacking this into the current Facebook SDK.

查看更多
Luminary・发光体
3楼-- · 2019-05-11 00:43

You can't know when it gonna log you in but you can put an UIActivityIndicatorView. You start it when you click on publish button and you end it when you enter the 'didConnect' method

查看更多
登录 后发表回答