iOS Developer Library

Developer

MultipeerConnectivity Framework Reference MCPeerID Class Reference

Options
Deployment Target:

On This Page
Language:

MCPeerID

Inherits From


Conforms To


Import Statement


Swift

import MultipeerConnectivity

Objective-C

@import MultipeerConnectivity;

Availability


Available in iOS 7.0 and later

The MCPeerID class represents a peer in a multipeer session.

The Multipeer Connectivity framework is responsible for creating peer objects that represent other devices. Your app is responsible for creating a single peer object that represents the instance of your app that is running on the local device.

To create a new peer ID for the local app and associate a display name with that ID, call initWithDisplayName:. The peer’s name must be no longer than 63 bytes in UTF-8 encoding.

  • Initializes a peer.

    Declaration

    Swift

    init!(displayName myDisplayName: String!)

    Objective-C

    - (instancetype)initWithDisplayName:(NSString *)myDisplayName

    Parameters

    myDisplayName

    The display name for the local peer. If you use the multipeer browser view controller, this name is shown.

    The display name is intended for use in UI elements, and should be short and descriptive of the local peer. The maximum allowable length is 63 bytes in UTF-8 encoding. The displayName parameter may not be nil or an empty string.

    Return Value

    Returns an initialized object.

    Discussion

    This method should be called only when creating the local peer, not for creating objects that represent other devices.

    This method throws an exception if the displayName value is too long, empty, or nil.

    Import Statement

    Objective-C

    @import MultipeerConnectivity;

    Swift

    import MultipeerConnectivity

    Availability

    Available in iOS 7.0 and later

  • The display name for this peer. (read-only)

    Declaration

    Swift

    var displayName: String! { get }

    Objective-C

    @property(readonly, nonatomic) NSString *displayName

    Discussion

    For the local peer, this property is set when the object is initialized and cannot be changed.

    For other peer objects provided to you by the framework, this property is provided by the peer and cannot be changed.

    Import Statement

    Objective-C

    @import MultipeerConnectivity;

    Swift

    import MultipeerConnectivity

    Availability

    Available in iOS 7.0 and later