MCBrowserViewController Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/MultipeerConnectivity.framework
Availability
Available in iOS 7.0 and later.
Declared in
MCBrowserViewController.h

Overview

The MCBrowserViewController class presents nearby devices to the user and enables the user to invite nearby devices to a session. To use this class, call methods from the underlying UIViewController class (prepareForSegue:sender: and performSegueWithIdentifier:sender: for storyboards or presentViewController:animated:completion: and dismissViewControllerAnimated:completion: for nib-based views) to present and dismiss the view controller.

Tasks

Initializing a Browser View Controller

Getting and Setting the Maximum and Minimum Number of Peers

Properties

browser

The browser object that is used for discovering peers. (read-only)

@property(readonly, nonatomic) MCNearbyServiceBrowser *browser
Discussion

This value is set when you initialize the object, and cannot be changed later.

Availability
  • Available in iOS 7.0 and later.
Declared In
MCBrowserViewController.h

delegate

The delegate object that handles browser-view-controller-related events.

@property(assign, nonatomic) id<MCBrowserViewControllerDelegate> delegate
Discussion

A browser view controller notifies the delegate:

  • When the user presses the “Done” button, which is enabled when the specified minimum number of peers are connected in a session.

  • When the user cancels the view controller.

Also, as new peers are discovered, the delegate can choose whether to present them in the user interface.

Availability
  • Available in iOS 7.0 and later.
Declared In
MCBrowserViewController.h

maximumNumberOfPeers

The maximum number of peers allowed in a session, including the local peer.

@property(assign, nonatomic) NSUInteger maximumNumberOfPeers
Discussion

The largest allowable value (and the default) is 8.

Availability
  • Available in iOS 7.0 and later.
Declared In
MCBrowserViewController.h

minimumNumberOfPeers

The minimum number of peers that need to be in a session, including the local peer.

@property(assign, nonatomic) NSUInteger minimumNumberOfPeers
Discussion

The smallest allowable value (and the default) is 2.

Availability
  • Available in iOS 7.0 and later.
Declared In
MCBrowserViewController.h

session

The multipeer session to which the invited peers are connected. (read-only)

@property(readonly, nonatomic) MCSession *session
Discussion

This value is set when you initialize the object, and cannot be changed later.

Availability
  • Available in iOS 7.0 and later.
Declared In
MCBrowserViewController.h

Instance Methods

initWithBrowser:session:

Initializes a browser view controller with the provided browser and session.

- (instancetype)initWithBrowser:(MCNearbyServiceBrowser *)browser session:(MCSession *)session
Parameters
browser

An object that the browser view controller uses for browsing. This is usually an instance of MCNearbyServiceBrowser. However, if your app is using a custom discovery scheme, you can instead pass any custom subclass that calls the methods defined in the MCNearbyServiceBrowserDelegate protocol on its delegate when peers are found and lost.

Important: If you want the browser view controller to manage the browsing process, the browser object must not be actively browsing, and its delegate must be nil.

session

The multipeer session into which the invited peers are connected.

Return Value

Returns an initialized object, or nil if an error occurred.

Discussion

This method throws an exception if the browser or session parameters do not contain valid objects.

Availability
  • Available in iOS 7.0 and later.
Declared In
MCBrowserViewController.h

initWithServiceType:session:

Initializes a browser view controller using the provided service type and session.

- (instancetype)initWithServiceType:(NSString *)serviceType session:(MCSession *)session
Parameters
serviceType

The type of service to browse for. This should be a short text string that describes the app's networking protocol, in the same format as a Bonjour service type:

  • Must be 1–15 characters long

  • Can contain only ASCII lowercase letters, numbers, and hyphens.

This name should be easily distinguished from unrelated services. For example, a text chat app made by ABC company could use the service type abc-txtchat.

For more details, read “Domain Naming Conventions”.

session

The multipeer session that any user-chosen peers should be invited to join.

Return Value

Returns an initialized object, or nil if an error occurred.

Discussion

This method throws an exception if the session or serviceType parameters do not contain valid objects or the specified Bonjour service type is not valid.

Availability
  • Available in iOS 7.0 and later.
Declared In
MCBrowserViewController.h