Upgrade to Pro — share decks privately, control downloads, hide ads and more …

iBeacons and RubyMotion

willrax
March 18, 2014

iBeacons and RubyMotion

What are they and how do I use them? Presented at the Sydney RubyMotion Meet up, #sydinmotion.

willrax

March 18, 2014
Tweet

More Decks by willrax

Other Decks in Programming

Transcript

  1. What are they? Built on Bluetooth 4.0. Extremely Low Powered.

    Protocol designed by Apple. #sydinmotion
  2. #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)
  3. #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
  4. Registering a Beacon Region Entering a Region Ranging any Beacons

    (proximity) Exiting the Region #sydinmotion
  5. 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
  6. Register the Beacon Region #sydinmotion Must Launch your App Limit

    of 20 Beacons Persist after closure of your App (iOS 7.1)
  7. 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
  8. 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
  9. 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
  10. ! ! 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
  11. ! ! 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
  12. ! ! 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
  13. 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