Share
Embed
iBeacons and RubyMotion
What are they and how do I use them? Presented at the Sydney RubyMotion Meet up, #sydinmotion.
willrax
March 18, 2014
Transcript
30 slides
-
What are they? Built on Bluetooth 4.0. Extremely Low Powered.
Protocol designed by Apple. #sydinmotion -
#sydinmotion class BeaconViewController < UIViewController ! ! ! ! !
! ! ! ! ! ! ! ! ! ! ! ! ! ! end def viewDidLoad super ! ! ! ! ! ! end uuid = NSUUID.alloc.initWithUUIDString("7cbff8c6-4d84-4e8c-8703-377e03d4f69f") @region = CLBeaconRegion.alloc.initWithProximityUUID(uuid, identifier: “com.wr.reg") queue = Dispatch::Queue.main.dispatch_object @manager = CBPeripheralManager.alloc.initWithDelegate(self, queue: queue) -
#sydinmotion class BeaconViewController < UIViewController ! ! ! ! !
! ! ! ! ! ! ! ! ! ! ! ! ! ! end def viewDidLoad super ! ! ! ! ! ! end def peripheralManagerDidUpdateState(peripheral) ! ! ! end uuid = NSUUID.alloc.initWithUUIDString("7cbff8c6-4d84-4e8c-8703-377e03d4f69f") @region = CLBeaconRegion.alloc.initWithProximityUUID(uuid, identifier: “com.wr.reg") queue = Dispatch::Queue.main.dispatch_object @manager = CBPeripheralManager.alloc.initWithDelegate(self, queue: queue) if peripheral.state == CBPeripheralManagerStatePoweredOn @manager.startAdvertising @region.peripheralDataWithMeasuredPower(nil) end -
Registering a Beacon Region Entering a Region Ranging any Beacons
(proximity) Exiting the Region #sydinmotion -
Registering a Beacon Region Entering a Region Ranging any Beacons
(proximity) Exiting the Region location_manager.startMonitoringForRegion(beacon_region) locationManager(manager, didEnterRegion: region) locationManager(manager, didRangeBeacons: beacons, inRegion: region) locationManager(manager, didExitRegion: region) #sydinmotion -
Register the Beacon Region #sydinmotion Must Launch your App Limit
of 20 Beacons Persist after closure of your App (iOS 7.1) -
class BeaconController < UIViewController def beacon_region ! ! ! !
! ! end uuid = NSUUID.alloc.initWithUUIDString("1609DCB3-F641-4231-8B12-70129AAFE0DE") beacon = CLBeaconRegion.alloc.initWithProximityUUID(uuid, identifier: “com.willrax.s") beacon.notifyOnEntry = true beacon.notifyOnExit = true beacon.notifyEntryStateOnDisplay = true beacon #sydinmotion -
class BeaconController < UIViewController def beacon_region ! ! ! !
! ! end uuid = NSUUID.alloc.initWithUUIDString("1609DCB3-F641-4231-8B12-70129AAFE0DE") beacon = CLBeaconRegion.alloc.initWithProximityUUID(uuid, identifier: “com.willrax.s") beacon.notifyOnEntry = true beacon.notifyOnExit = true beacon.notifyEntryStateOnDisplay = true beacon def location_manager ! ! ! end @location_manager ||= CLLocationManager.alloc.init.tap do |manager| manager.delegate = self end #sydinmotion -
class BeaconController < UIViewController def beacon_region ! ! ! !
! ! end uuid = NSUUID.alloc.initWithUUIDString("1609DCB3-F641-4231-8B12-70129AAFE0DE") beacon = CLBeaconRegion.alloc.initWithProximityUUID(uuid, identifier: “com.willrax.s") beacon.notifyOnEntry = true beacon.notifyOnExit = true beacon.notifyEntryStateOnDisplay = true beacon def location_manager ! ! ! end @location_manager ||= CLLocationManager.alloc.init.tap do |manager| manager.delegate = self end def viewDidLoad super end location_manager.startMonitoringForRegion(beacon_region) #sydinmotion -
! ! end manager.delegate = self end def viewDidLoad super
end location_manager.startMonitoringForRegion(beacon_region) def locationManager(manager, didEnterRegion: region) end manager.startRangingBeaconsInRegion(region) if region.isKindOfClass(CLBeaconRegion) end #sydinmotion -
! ! end manager.delegate = self end def viewDidLoad super
end location_manager.startMonitoringForRegion(beacon_region) def locationManager(manager, didRangeBeacons: beacons, inRegion: region) ! ! ! end def locationManager(manager, didEnterRegion: region) end manager.startRangingBeaconsInRegion(region) if region.isKindOfClass(CLBeaconRegion) if beacons.last.proximity == CLProximityImmediate end Broadcast.new("Office Arrival: willrax" ).send end #sydinmotion -
! ! end manager.delegate = self end def viewDidLoad super
end location_manager.startMonitoringForRegion(beacon_region) def locationManager(manager, didRangeBeacons: beacons, inRegion: region) ! ! ! end def locationManager(manager, didEnterRegion: region) end def locationManager(manager, didExitRegion: region) ! ! ! ! end manager.startRangingBeaconsInRegion(region) if region.isKindOfClass(CLBeaconRegion) if region.isKindOfClass(CLBeaconRegion) ! ! end if beacons.last.proximity == CLProximityImmediate end manager.stopRangingBeaconsInRegion(region) Broadcast.new("Office Departure: willrax" ).send Broadcast.new("Office Arrival: willrax" ).send end #sydinmotion -
bit.ly/blog-ibeacon bit.ly/ibeacon-app iBeacons and RubyMotion Blog Post Example Transmitter and
Finder bit.ly/motion-arrivals Presentation Example Code #sydinmotion bit.ly/beaconpi bit.ly/clbeacon Raspberry Pi as iBeacon CLBeacon Class Reference bit.ly/beaconosx Beacon Emitter for OSX