iOS Developer Library — Prerelease

Developer

Multipeer Connectivity Framework Reference MCNearbyServiceBrowser Class Reference

Options
Deployment Target:

On This Page
Language:

MCNearbyServiceBrowser

Searches (by service type) for services offered by nearby devices using infrastructure Wi-Fi, peer-to-peer Wi-Fi, and Bluetooth, and provides the ability to easily invite those devices to a Multipeer Connectivity session (MCSession).

  • Initializes the nearby service browser object.

    Declaration

    Swift

    init(peer myPeerID: MCPeerID, serviceType serviceType: String)

    Objective-C

    - (instancetype nonnull)initWithPeer:(MCPeerID * nonnull)myPeerID serviceType:(NSString * nonnull)serviceType

    Parameters

    myPeerID

    The local peer ID for this instance.

    serviceType
    • 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.

    Return Value

    Returns an initialized nearby service browser object, or nil if an error occurs.

    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.

  • The delegate object that handles browser-related events.

    Declaration

    Swift

    weak var delegate: MCNearbyServiceBrowserDelegate?

    Objective-C

    @property(weak, nonatomic) id< MCNearbyServiceBrowserDelegate > delegate

    Availability

    Available in iOS 7.0 and later.

  • The local peer ID for this instance. (read-only)

    Declaration

    Swift

    var myPeerID: MCPeerID { get }

    Objective-C

    @property(readonly, nonatomic) MCPeerID *myPeerID

    Discussion

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

    Availability

    Available in iOS 7.0 and later.

  • The service type to browse for. (read-only)

    Declaration

    Swift

    var serviceType: String { get }

    Objective-C

    @property(readonly, nonatomic) NSString *serviceType

    Discussion

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

    Availability

    Available in iOS 7.0 and later.

  • Invites a discovered peer to join a Multipeer Connectivity session.

    Declaration

    Swift

    func invitePeer(_ peerID: MCPeerID, toSession session: MCSession, withContext context: NSData?, timeout timeout: NSTimeInterval)

    Objective-C

    - (void)invitePeer:(MCPeerID * nonnull)peer toSession:(MCSession * nonnull)session withContext:(NSData * nullable)context timeout:(NSTimeInterval)timeout

    Parameters

    peer

    The ID of the peer to invite.

    session

    The session you wish the invited peer to join.

    context

    An arbitrary piece of data that is passed to the nearby peer. This can be used to provide further information to the user about the nature of the invitation.

    timeout

    The amount of time to wait for the peer to respond to the invitation.

    This timeout is measured in seconds, and must be a positive value. If a negative value or zero is specified, the default timeout (30 seconds) is used.

    Availability

    Available in iOS 7.0 and later.