Skip to content

Instantly share code, notes, and snippets.

@kent013
Created December 13, 2011 12:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kent013/1471906 to your computer and use it in GitHub Desktop.
Save kent013/1471906 to your computer and use it in GitHub Desktop.
Add feature to check upload progress in FBRequest
//
// FBRequest+UploadProgress.h
// tottepost
//
// Created by ISHITOYA Kentaro on 11/12/13.
// Copyright (c) 2011 cocotomo. All rights reserved.
//
#import "FBRequest.h"
@protocol FBRequestWithUploadProgressDelegate;
@interface FBRequest(UploadProgress)
@end
@protocol FBRequestWithUploadProgressDelegate <FBRequestDelegate>
@optional
/**
* Called as the body (message data) of a request
* is transmitted (as during an http POST). It provides the number of bytes
* written for the latest write, the total number of bytes written and the
* total number of bytes the connection expects to write (for HTTP this is
* based on the content length). The total number of expected bytes may change
* if the request needs to be retransmitted (underlying connection lost, authentication
* challenge from the server, etc.).
* See https://github.com/johnmph/facebook-ios-sdk for more information.
*
* @param bytesWritten number of bytes written
* @param totalBytesWritten total number of bytes written for this connection
* @param totalBytesExpectedToWrite the number of bytes the connection expects to write (can change due to retransmission of body content)
*/
- (void)request:(FBRequest *)request didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite;
@end
//
// FBRequest+UploadProgress.m
// tottepost
//
// Created by ISHITOYA Kentaro on 11/12/13.
// Copyright (c) 2011 cocotomo. All rights reserved.
//
#import "FBRequest+UploadProgress.h"
@implementation FBRequest(UploadProgress)
/*!
* delegate for upload progress
*/
- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite {
id<FBRequestWithUploadProgressDelegate> d = (id<FBRequestWithUploadProgressDelegate>)_delegate;
if ([d respondsToSelector:
@selector(request:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:)]) {
[d request:self didSendBodyData:bytesWritten totalBytesWritten:totalBytesWritten totalBytesExpectedToWrite:totalBytesExpectedToWrite];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment