I'm working on a project that uses MC framework as a communication channel, and after some tests I have the perception that this channel is somehow unstable to rely on.
I've been following Apple's documentations and videos in order to use the framework properly, but happens that:
Is there any kind of recommendation to work with the framework? i.e:
I found this link that mentions something about the framework not performing ok under stress. That's the kind of advice I'm looking for :).
For the record:
MCSession
for all peers I try to pair withMCEncryptionNone
sendData:
and sendResourceAtURL:
to communicate with peers.The Multipeer Connectivity framework supports the discovery of services provided by nearby devices and supports communicating with those services through message-based data, streaming data, and resources (such as files).
Here, the app uses Apple's Multipeer Connectivity framework, essentially a peer-to-peer feature that lets you share messages (and soon photos) with other app users nearby, regardless of whether you have an actual Wi-Fi or cellular connection.
I'm using the MC framework in a game and have found a few workarounds for its apparent instability:
1) I use a "keep alive" transaction sent every 15 seconds to maintain activity on the links. I found that this resolves almost all the connection losses I was experiencing.
2) I dispatch all processing triggered by data reception to the main thread and never carry any MCPeer nor MCSession objects between threads (except for the initial connection protocol). I also did that to minimize the time spent in the data reception code so that the thread used by MC regains control as fast as possible (which I also found was a source of some disconnects). I do not apply this rule for sending data (only when receiving)
3) I have NOT found a clean solution to the repetition of peers that appears when trying to establish a connection (both using the standard UI and my own). So far comparing MCPeer IDs to avoid duplicates only seems to remove some of the duplication. Also, it seemed that using the same MCSession for advertising (MCAdvertiserAssistant) and connecting to peers caused some conflicts so i'm using a new, separate MCSession instance every time I start the assistant.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With