iBeacons and RubyMotion

14baad19117f310a997de06583f9b48e?s=47 willrax
March 18, 2014

iBeacons and RubyMotion

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

14baad19117f310a997de06583f9b48e?s=128

willrax

March 18, 2014
Tweet

Transcript

  1. iBeacons #sydinmotion

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

    Protocol designed by Apple. #sydinmotion
  3. #sydinmotion

  4. Emit a Beacon

  5. #sydinmotion

  6. UUID

  7. Major UUID

  8. Minor Major UUID

  9. Transmitting #sydinmotion

  10. #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)
  11. #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
  12. Searching #sydinmotion

  13. Registering a Beacon Region Entering a Region Ranging any Beacons

    (proximity) Exiting the Region #sydinmotion
  14. 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
  15. Ranging Beacons! CLProximityUnknown CLProximityFar CLProximityNear CLProximityImmediate #sydinmotion ?

  16. Gotchas #sydinmotion

  17. Register the Beacon Region #sydinmotion Must Launch your App Limit

    of 20 Beacons Persist after closure of your App (iOS 7.1)
  18. Example #sydinmotion

  19. Office Arrivals and Departures #sydinmotion

  20. #sydinmotion

  21. 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
  22. 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
  23. 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
  24. ! ! 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
  25. ! ! 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
  26. ! ! 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
  27. Real World #sydinmotion

  28. bit.ly/FormaQ bit.ly/tillless FormaQ Tillless bit.ly/awwapps ˑ*Aww Apps*ˑኯ #sydinmotion

  29. uestions? #sydinmotion @willrax

  30. 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