iOS Developer Library

Developer

MultipeerConnectivity Framework Reference MCAdvertiserAssistant Class Reference

Options
Deployment Target:

On This Page
Language:

MCAdvertiserAssistant

The MCAdvertiserAssistant is a convenience class that handles advertising, presents incoming invitations to the user and handles users’ responses. This class should be used to provide a user interface for handling invitations when your app does not require programmatic control over the invitation process. More...

Inheritance


Conforms To


Import Statement


import MultipeerConnectivity @import MultipeerConnectivity;

Availability


Available in iOS 7.0 and later.
  • delegate delegate Property

    The delegate object that handles advertising-assistant-related events.

    Declaration

    Swift

    weak var delegate: MCAdvertiserAssistantDelegate!

    Objective-C

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

    Import Statement

    import MultipeerConnectivity

    Availability

    Available in iOS 7.0 and later.

  • The info dictionary that was passed when this object was initialized. (read-only)

    Declaration

    Swift

    var discoveryInfo: [NSObject : AnyObject]! { get }

    Objective-C

    @property(readonly, nonatomic) NSDictionary *discoveryInfo

    Discussion

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

    Import Statement

    import MultipeerConnectivity

    Availability

    Available in iOS 7.0 and later.

  • The service type that your app is advertising. (read-only)

    Declaration

    Swift

    var serviceType: String! { get }

    Objective-C

    @property(readonly, nonatomic) NSString *serviceType

    Discussion

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

    Import Statement

    import MultipeerConnectivity

    Availability

    Available in iOS 7.0 and later.

  • Begins advertising the service provided by a local peer and starts the assistant.

    Declaration

    Swift

    func start()

    Objective-C

    - (void)start

    Import Statement

    import MultipeerConnectivity

    Availability

    Available in iOS 7.0 and later.

  • Stops advertising the service provided by a local peer and stops the assistant.

    Declaration

    Swift

    func stop()

    Objective-C

    - (void)stop

    Import Statement

    import MultipeerConnectivity

    Availability

    Available in iOS 7.0 and later.

  • Initializes an advertiser assistant object.

    Declaration

    Swift

    init!(serviceType serviceType: String!, discoveryInfo info: [NSObject : AnyObject]!, session session: MCSession!)

    Objective-C

    - (instancetype)initWithServiceType:(NSString *)serviceType discoveryInfo:(NSDictionary *)info session:(MCSession *)session

    Parameters

    serviceType

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

    • 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 in Bonjour Overview.

    info

    A dictionary of key-value pairs that are made available to browsers. Each key and value must be an NSString object.

    This data is advertised using a Bonjour TXT record, encoded according to RFC 6763 (section 6). As a result:

    • The key-value pair must be no longer than 255 bytes (total) when encoded in UTF-8 format with an equals sign (=) between the key and the value.

    • Keys cannot contain an equals sign.

    For optimal performance, the total size of the keys and values in this dictionary should be no more than about 400 bytes so that the entire advertisement can fit within a single Bluetooth data packet. For details on the maximum allowable length, read Monitoring a Bonjour Service in NSNetServices and CFNetServices Programming Guide.

    If the data you need to provide is too large to fit within these constraints, you should create a custom discovery class using Bonjour for discovery and your choice of networking protocols for exchanging the information.

    session

    The session into which new peers should be added after they accept the invitation.

    Return Value

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

    Discussion

    This method throws an exception if a valid peerID object is not provided or if serviceType is not a legal Bonjour service type.

    Import Statement

    import MultipeerConnectivity

    Availability

    Available in iOS 7.0 and later.

  • session session Property

    The session into which new peers are added after accepting an invitation. (read-only)

    Declaration

    Swift

    var session: MCSession! { get }

    Objective-C

    @property(readonly, nonatomic) MCSession *session

    Discussion

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

    Import Statement

    import MultipeerConnectivity

    Availability

    Available in iOS 7.0 and later.