There are several types of objects in this mesh network to work with:
- Session objects (
MCSession) provide support for communication between connected peer devices. If your app creates a session, it can invite other peers to join it. Otherwise, your app can join a session when invited by another peer.
- Advertiser objects (
MCNearbyServiceAdvertiser) tell nearby peers that your app is willing to join sessions of a specified type.
- Advertiser assistant objects (
MCAdvertiserAssistant) provide the same functionality as advertiser objects, but also provide a standard user interface that allows the user to accept invitations. If you wish to provide your own user interface, or if you wish to exercise additional programmatic control over which invitations are displayed, use an advertiser object directly.
- Browser objects (
MCNearbyServiceBrowser) let your app search programmatically for nearby devices with apps that support sessions of a particular type.
- Browser view controller objects (
MCBrowserViewController) provide a standard user interface that allows the user to choose nearby peers to add to a session.
- Peer IDs (
MCPeerID) uniquely identify an app running on a device to nearby peers.
Session objects maintain a set of peer ID objects that represent the peers connected to the session. Advertiser objects also use a single local peer object to provide information that identifies the device and its user to other nearby devices.
In the discovery phase, your app uses a browser object (described in MCNearbyServiceBrowser Class Reference) to browse for nearby peers, optionally using the provided view controller (described in MCBrowserViewController Class Reference) to display a user interface.
The app also uses an advertiser object (described in MCNearbyServiceAdvertiser Class Reference) or an advertiser assistant object (described in MCAdvertiserAssistant Class Reference) to tell nearby peers that it is available so that apps on other nearby devices can invite it to a session.
During the discovery phase, your app has limited communication with and knowledge of other peers; it has access to the
discoveryInfodata that other nearby clients provide, and any context data that other peers provide when inviting it to join a session.
After the user chooses which peers to add to a session, the app invites those peers to join the session. Apps running on the nearby devices can choose whether to accept or reject the invitation, and can ask their users for permission.
If the peer accepts the invitation, the browser establishes a connection with the advertiser and the session phase begins. In this phase, your app can perform direct communication to one or more peers within the session. The framework notifies your app through delegate callbacks when peers join the session and when they leave the session.The FireChat app, developed by Open Garden released in the last week makes use of this feature. This feature allows phones to connect to one another directly using Bluetooth or Wi-Fi as an alternative to the Internet. If you’re using FireChat, its “nearby” chat room lets you exchange messages with other users within 100 feet without sending data via your cellular provider.
The new feature of iOS7 currently only supports data moving directly from one device to another, and from one device to several others. However, the FireChat will extend the feature so that data can hop between two iPhones out of range of one another via intermediary devices. That approach, known as mesh networking, is at the heart of several existing projects to create disaster-proof or community-controlled communications networks.