How to get progress for transfer with Multipeer Connectivity

I want to know the proper way to get progress when you send / receive large data (like an image) with Multipeer Connectivity Framework which appeared in iOS 7.
- (BOOL)sendData:(NSData *)data toPeers:(NSArray *)peerIDs withMode:(MCSessionSendDataMode)mode error:(NSError **)error
↑MCSession class has this method and you can send NSData-type data.
-(void)session:(MCSession *)session didReceiveData:(NSData *)data fromPeer:(MCPeerID *)peerID
↑You can receive the data with this MCSessionDelegate method.

I suppose there is a 1000 bytes limit with GKSession class. But you can transfer data which is much larger than 1000 bytes with methods above.
But it is impossible to get progress while transferring.
Image data is so large, it may take 10 seconds or more, therefore I want to show a progress bar.

So I tried next methods :
- (NSProgress *)sendResourceAtURL:(NSURL *)resourceURL withName:(NSString*)resourceName toPeer:(MCPeerID *)peerID withCompletionHandler:(void (^)(NSError *error))completionHandler
↑You can also send image data with this method. You have to save your image data at first.

- (void)session:(MCSession *)session didStartReceivingResourceWithName:(NSString *)resourceName fromPeer:(MCPeerID *)peerID withProgress:(NSProgress *)progress

- (void)session:(MCSession *)session didFinishReceivingResourceWithName:(NSString *)resourceName fromPeer:(MCPeerID *)peerID atURL:(NSURL *)localURL withError:(NSError *)error
↑You can get the start and end of transfer and its progress as NSProgress object with methods above which are both MCSessionDelegate methods.

I actually succeeded to transfer image data with showing progress bar, but this way does not look smart…? Any other way?
Develop | Comments(0) | Trackback(0)