iOS Developer Library

Developer

MultipeerConnectivity Framework Reference MCBrowserViewController Class Reference

Options
Deployment Target:

On This Page
Language:

MCBrowserViewController

Inherits From


Import Statement


Swift

import MultipeerConnectivity

Objective-C

@import MultipeerConnectivity;

Availability


Available in iOS 7.0 and later

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.

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

    Declaration

    Swift

    convenience init!(serviceType serviceType: String!, session session: MCSession!)

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import MultipeerConnectivity;

    Swift

    import MultipeerConnectivity

    Availability

    Available in iOS 7.0 and later

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

    Declaration

    Swift

    init!(browser browser: MCNearbyServiceBrowser!, session session: MCSession!)

    Objective-C

    - (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.

    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.

    Import Statement

    Objective-C

    @import MultipeerConnectivity;

    Swift

    import MultipeerConnectivity

    Availability

    Available in iOS 7.0 and later

  • delegate delegate Property

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

    Declaration

    Swift

    weak var delegate: MCBrowserViewControllerDelegate!

    Objective-C

    @property(weak, 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.

    Import Statement

    Objective-C

    @import MultipeerConnectivity;

    Swift

    import MultipeerConnectivity

    Availability

    Available in iOS 7.0 and later

  • browser browser Property

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

    Declaration

    Swift

    var browser: MCNearbyServiceBrowser! { get }

    Objective-C

    @property(readonly, nonatomic) MCNearbyServiceBrowser *browser

    Discussion

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

    Import Statement

    Objective-C

    @import MultipeerConnectivity;

    Swift

    import MultipeerConnectivity

    Availability

    Available in iOS 7.0 and later

  • session session Property

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

    Declaration

    Swift

    var session: MCSession! { get }

    Objective-C

    @property(readonly, nonatomic) MCSession *session

    Discussion

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

    Import Statement

    Objective-C

    @import MultipeerConnectivity;

    Swift

    import MultipeerConnectivity

    Availability

    Available in iOS 7.0 and later

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

    Declaration

    Swift

    var maximumNumberOfPeers: Int

    Objective-C

    @property(assign, nonatomic) NSUInteger maximumNumberOfPeers

    Discussion

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

    Import Statement

    Objective-C

    @import MultipeerConnectivity;

    Swift

    import MultipeerConnectivity

    Availability

    Available in iOS 7.0 and later

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

    Declaration

    Swift

    var minimumNumberOfPeers: Int

    Objective-C

    @property(assign, nonatomic) NSUInteger minimumNumberOfPeers

    Discussion

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

    Import Statement

    Objective-C

    @import MultipeerConnectivity;

    Swift

    import MultipeerConnectivity

    Availability

    Available in iOS 7.0 and later