问题描述
我想在iPhone应用程序将图像上传到Facebook时显示进度条。可以吗?
I want to show a progress bar while my iPhone app is uploading an image to Facebook. Is it possible?
我可以用每个FBRequest来做吗?我也使用FBRequest检查扩展许可,有时需要很多时间。
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.
谢谢。
推荐答案
对于进度条,你可以做一些小黑客。在 FBRequest.h
文件添加此行中的 FBRequestDelegate
协议:
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;
之后在 FBRequest.m
文件添加此功能:
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);
}
如果您有任何问题将其侵入当前的Facebook SDK,请告诉我们。
Let me know if you have any problems hacking this into the current Facebook SDK.
这篇关于Facebook iPhone SDK:在上传图像时显示进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!