0

Iam using multipeer connectivity feature in my app. I have a weird problem ie, Iam able to send and receive messages(chatting). But in case of file sharing, I use

sendResourceAtURL:resourceURL withName:fileName toPeer:peer1

But While sending large files ie(more than 1Mb) the app crashes ie when i share a file taken from the photos app using image picker controller.Also Multipeer connectivity doesn't support breakpoints, i cant debug it. Any possible solutions for it? is it a memory issue (crashes due to high memory usage?) Iam using ios 8.1.3(device) and ios 8 simulator. i also checked b/w two devices,but still same crash.Please Help!!!!

DHEERAJ
  • 1,478
  • 12
  • 32
  • Which app crashes? The one sending or the one receiving? Please post code. Impossible to help without seeing what you are doing. – ChrisH Feb 11 '15 at 19:56
  • Hi, I'm experiencing exaclty the same problems, have you found a way to improve / correct this ? Thnks – FlavienSi Oct 27 '15 at 13:54

1 Answers1

1

Sending data or files with multi-peer connectivity only works for small quantities of data - a few kilobytes is ok, but sending more than about a megabyte will cause it to fail. If you need to send more you need to use streams. To establish the output stream, start it when the session is established

-(void)session:(MCSession *)session peer:(MCPeerID *)peerID didChangeState:(MCSessionState)state
{
    switch(state)
    {
        // ...
        case MCSessionStateConnected:
            self.outputStream = [session startStreamWithName:@"Stream" toPeer:weakSelf.remotePeerID error:&error];
            break;
        // ...
    }
}

And for your input stream, implement

-(void)session:(MCSession *)session didReceiveStream:(NSInputStream  *)stream withName:(NSString *)streamName fromPeer:(MCPeerID *)peerID
{
    self.inputStream = stream;
}

Once you have a both streams you can open them and start reading and writing.

DavidA
  • 3,112
  • 24
  • 35