AirNativeiOS-Bluetooth is a native extension to add Bluetooth support for iOS apps. The API mirrors the Objective-C API found in Apple GameKit and supports the features of the GKPeerPickerController and relative GKSession features only.

The extension provides enough functionality to connect with another Peer via the default iOS Bluetooth pop-up and send messages between each other.


// instantiating a connection
var p2p:GKPeerToPeer = new GKPeerToPeer();
var picker:GKPeerPickerController = p2p.createGKPeerPickerController();

// wait for these events to know we've connected..
picker.addEventListener(GKPeerPickerControllerEvent.DID_CONNECT_PEER, onGKPeerPickerControllerEvent, false, 0, true );
picker.addEventListener(GKPeerPickerControllerEvent.CONTROLLER_DID_CANCEL, onGKPeerPickerControllerEvent, false, 0, true );

// the event handler for one of the above methods would contain:
picker.removeEventListener(GKPeerPickerControllerEvent.DID_CONNECT_PEER, onGKPeerPickerControllerEvent );
picker.removeEventListener(GKPeerPickerControllerEvent.CONTROLLER_DID_CANCEL, onGKPeerPickerControllerEvent );

picker.dismiss(); // hides the iOS popup after connection.
picker.dispose(); // remember to dispose!!

// access the new GKSession object now we've connected.
var session:GKSession = p2p.session;

// then send a message
session.sendDataToAllPeers( "Hello!", GKSendDataMode.RELIABLE );

// after use, disconnect and dispose
Air Native Extension, iOS . URL.