Giter Site home page Giter Site logo

airnativeios-bluetooth's Introduction

AirNativeiOS-Bluetooth

Description

AIR Native Extension to add Bluetooth support for iOS apps. The Actionscript API mirrors the Objective-C API found in Apple GameKit. To get a better understanding of Bluetooth on iOS read the Peer-to-Peer documentation found on the Apple GameKit Programming Guide. And also the class reference for GKSession and GKPeerPickerController.

Usage

The native extension currently supports the features of the GKPeerPickerController and relative GKSession features only. This provides enough functionality to connect with another Peer via the default iOS Bluetooth pop-up and send messages between each other. You can view a video demo of this below, and the source for the video example is in the respository. See Improvements below for additional functionality.

A rough example looks like :

'''as

	// 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
	session.disconnectFromAllPeers();
	session.dispose();

'''

Video

Demo showing features of GKPeerPickerController basics.. http://www.youtube.com/watch?v=Tdh0DBYAtOo

Improvements

The full features of the GKSession object are implemented in Actionscript and C/Objective-C side but are commented out at the moment until I get a chance to test properly (testing bluetooth takes longer than usual!). Please feel free to fork this repository and uncomment the code. Let me know if you test and finish it! The additional features would enable :

  • Establishing a GKSession manually with possibilty to connect to multiple peers.
  • Building a custom peer picker interface to show available peers.
  • Sending data to specific peers.
  • Basically anything in the GameKit Peer-to-Peer docs.

airnativeios-bluetooth's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.