CanIOManager

Class Overview

A singleton class used as the main interface for interacting with CanIO. This class is used to advertise, browse for and discover peers, and for sending and receiving requests and responses.

Properties

@property (nonatomic, assign) id <CanIODelegate> delegate;

CanIOManager's delegate, conforming to the CanIODelegate protocol. This protocol is used to notify your app about newly discovered peers and new information about peers, and for incoming requests and responses.

@property (nonatomic) NSMutableArray *peers;

An array of CanIOPeer objects containing the current discovered peers.

Methods

- (void)startServices;

Use to start CanIO services. This method must be called before any CanIOManager is called.

- (void)startAdvertising;
- (void)stopAdvertising;

Use these methods to start and stop advertising the local peer to nearby peers over all available network interfaces. When your local peer is advertising, you will be discoverable to other peers.

Please note that when your local peer stops advertising, you will not be discoverable, unless your local peers discovers a peer, in which case the other peer will discover the local peer.

- (void)startDiscoveringPeers;
- (void)stopDiscoveringPeers;

Use these methods to start and stop discovery of nearby peers. When discovering peers, any nearby advertising peer will be discovered, adding it to the peers array and triggering the didDiscoverPeer: delegate method.

Please note that when discovery is turned off, you may still discover peers if your local peer is advertising itself and is detected by another peer, at which point the other peer will be discovered.

- (void)sendRequest:(CanIORequest *)request toPeer:(CanIOPeer *)peer;
- (void)sendRequest:(CanIORequest *)request
             toPeer:(CanIOPeer *)peer
            success:(void (^)(CanIOConnectionOperation *operation, id responseObject))success
            failure:(void (^)(CanIOConnectionOperation *operation, NSError *error))failure;

Use these methods to send a CanIORequest to a peer. The second method allows you to define success and failure blocks, which will be called in case the request succeeds or fails.

- (void)sendResponse:(CanIOResponse *)response toPeer:(CanIOPeer *)peer;
- (void)sendResponse:(CanIOResponse *)response
             toPeer:(CanIOPeer *)peer
            success:(void (^)(CanIOConnectionOperation *operation, id responseObject))success
            failure:(void (^)(CanIOConnectionOperation *operation, NSError *error))failure;

Use these methods to send a CanIOResponse to a peer. The second method allows you to define success and failure blocks, which will be called in case the request succeeds or fails.