Search code examples
iosobjective-cios7multipeer-connectivitymcsession

Sending file with MCSession between iOS Simulator and Device


I have an application for iPad that needs to send files from one device to another with peer Apple's Multipeer Connectivity library. The file is a zip file (I'm using ZipArchive for iOS: https://github.com/mattconnolly/ZipArchive) and I'm testing it with the iOS Simulator and one iPad device. When I send the file from the iPad to the simulator it always works perfectly, but when I try to send it from the simulator to the device it fails 90% of the time. The zip file gets through, but a couple of kilobytes are missing from the end, so it cannot be uncompressed. I'm using the MCSession class and it's sendResourceAtURL function for the transfer:

// self.session is an MCSession object
[self.session sendResourceAtURL:archiveUrl withName:resourceName toPeer:clientPeer withCompletionHandler:
 ^(NSError *error){
     if (error) {
         NSLog(@"File sending error: %@", error.localizedDescription);
     }
 }];
  • I extract the file in the didFinishReceivingResourceWithName delegate method (which runs on a background thread).
  • All the NSError variables are nil (when sending and receiving), there is nothing that would indicate any problem.
  • The size of the file doesn't really matter, it behaves the same way when it's 20 Kb and when it's over a megabyte.
  • The two peers never disconnect during the transmission (or after).

I logged the file size of the sent and received file 3 times:

2014-07-15 12:14:20.470 PeerTest[1139:481f] Sending  file with size of 1182911
2014-07-15 12:14:22.090 PeerTest[1481:1803] Received file with size of 1171552 // failed to extract files

2014-07-15 12:16:25.470 PeerTest[1139:481f] Sending  file with size of 1182911
2014-07-15 12:16:27.882 PeerTest[1481:5127] Received file with size of 1181472 // failed to extract files

2014-07-15 12:17:20.470 PeerTest[1139:481f] Sending  file with size of 1182911
2014-07-15 12:17:22.980 PeerTest[1481:650f] Received file with size of 1182911 // successfully extracted files

I only have one iPad at the moment and want to figure out why it only works in one direction. Any ideas?


Solution

  • I managed to solve the problem by upgrading from iOS 7.0 to 7.1 (upgrading XCode as well). Now the file works perfectly between 2 iPad devices, also between the simulator and one iPad device.