Facebook iPhone SDK: show a progress bar while uploading an image

facebook, iphone, progress-bar

Solution

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.

Problem

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.

Original source