These are various tutorials/how-tos, etc, available on the web, produced by the iOS development community. I plan on updating this post as/when I find more resources. Please get in contact if you have any resources you’d like to contribute to this list.
NSHipster on Multipeer Connectivity
You will find a great introduction to the whole Multipeer Connectivity framework on NSHipster. If you haven’t already, go read it, then come back here. Future posts I write on this topic will largely assume that you are familiar with the contents of the NSHipster article.
As of writing, there are a couple of issues with the posted NSHipster article.
First of all, when advertising a service, make sure to keep a strong reference to the MCNearbyServiceAdvertiser (e.g. in a property), otherwise when the object goes out of scope it will be deallocated (and hence advertising will stop):
Make sure, of course, to nil out your reference to the advertiser when you no longer need it!
The second issue is an actual bug. When browsing for nearby services, you have two options:
- Manually create a browser via the
MCNearbyServiceBrowserclass, and manage the UI yourself.
- Use the built-in
MCBrowserViewControllerto handle both UI and browsing.
The supplied example combines the two - first create a browser object, then pass it to the browser view controller. This is possible, but when doing so, you should not manually invoke
[browser startBrowsingForPeers] - the browser view controller does this automatically for you. Additionally, the browser view controller becomes the delegate for the browser.
So, the example code should be:
Unless you need the browser object for another reason, though, it is simpler to just let the browser view controller create a browser itself:
This is a great place to get help, as well as help others. See questions tagged
Besides NSHipster, I haven’t found many tutorials online about the Multipeer framework. Here is a sampling of what I have found so far:
- Understanding Multipeer Connectivity Framework in iOS 7, Gabriel Theodoropoulos, - Part 1 and Part 2
- Exploring the Multipeer Connectivity framework, Gabriel Theodoropoulos, Part 1: Project Setup and Part 2: Game Logic
Please feel free to let me know of any notable exceptions to the list above!
Demo projects on GitHub
Several people have developed demo projects showing how to approach writing multipeer code. A few examples are: