SwiftでのGeoFence機能実装

1a1d418bdf51cbf8fce1317f6c80a907?s=47 satoshi0212
August 20, 2016
6.1k

 SwiftでのGeoFence機能実装

1a1d418bdf51cbf8fce1317f6c80a907?s=128

satoshi0212

August 20, 2016
Tweet

Transcript

  1. 3.

    ࣗݾ঺հ ৽͍ٕ͠ज़ͱɺͦͷগ͠มΘͬͨ࢖͍ํ͕େ޷͖ ɹTechCrunch Tokyo 2015 Hackathon ༏ल৆ ɹMizuho.Hack ༏ल৆ ɹMicrosoft

    MPC Hackathon TMCN৆ ɹHack Cars Days 2015 χϑςΟ৆ ɹMUSICIANS HACKATHON 2015 ༏ल৆ ɹɹͳͲ
  2. 12.

    1 Standard Location 2 Background Location Session 3 Beacon Ranging

    4 Geographical Region Monitoring 5 Visit Monitoring 6 Significant Location Change Monitoring Ґஔ৘ใ࣮૷ํ๏ͷ؆୯ͳ·ͱΊ
  3. 13.

    1 Standard Location ඪ४Ґஔ৘ใ 2 Background Location Session όοΫάϥ΢ϯυ ͰͷҐஔ৘ใ

    3 Beacon Ranging ϏʔίϯྖҬ؍ଌ 4 Geographical Region Monitoring ஍ཧతྖҬ؍ଌ 5 Visit Monitoring ๚໰ઌ௥੻ 6 Significant Location Change Monitoring େ෯มߋҐஔ৘ใ Ґஔ৘ใ࣮૷ํ๏ͷ؆୯ͳ·ͱΊ
  4. 14.

    4VTQFOEFE /PU3VOOJOH U3VOOJOH 1 Standard Location ඪ४Ґஔ৘ใ 2 Background Location

    Session όοΫάϥ΢ϯυ ͰͷҐஔ৘ใ 3 Beacon Ranging ϏʔίϯྖҬ؍ଌ ✔ 4 Geographical Region Monitoring ஍ཧతྖҬ؍ଌ ✔ 5 Visit Monitoring ๚໰ઌ௥੻ ✔ 6 Significant Location Change Monitoring େ෯มߋҐஔ৘ใ ✔ Ґஔ৘ใ࣮૷ํ๏ͷ؆୯ͳ·ͱΊ
  5. 15.

    4VTQFOEFE /PU3VOOJOH U3VOOJOH ಛ௃ 1 Standard Location ඪ४Ґஔ৘ใ 2 Background

    Location Session όοΫάϥ΢ϯυ ͰͷҐஔ৘ใ 3 Beacon Ranging ϏʔίϯྖҬ؍ଌ ✔ σόΠεઃஔ 4 Geographical Region Monitoring ஍ཧతྖҬ؍ଌ ✔ ೚ҙͷՕॴొ࿥ 5 Visit Monitoring ๚໰ઌ௥੻ ✔ ৔ॴొ࿥ͳ͠ 6 Significant Location Change Monitoring େ෯มߋҐஔ৘ใ ✔ େ͖͘Ҡಈͨ͠ ৔߹ Ґஔ৘ใ࣮૷ํ๏ͷ؆୯ͳ·ͱΊ
  6. 17.
  7. 22.
  8. 29.

    1. ਫ਼౓ͷݶք : 100m୯Ґ 2. ݕ஌λΠϛϯάͷ஗͞ : Outݕ஌͸1ʙ15෼ޙ ʮϢʔβͷҐஔ͕ྖҬͷڥքઢΛԣஅ͠ɺ͜ͷڥքઢ͔Β ࠷খڑ཭͚ͩ཭Ε͔ͯΒɺ͜ͷҐஔΛগͳ͘ͱ΋20ඵؒอ

    ࣋͠ͳ͍ͱɺ௨஌͸ใࠂ͞Ε·ͤΜɻʯ “Ґஔ৘ใͱϚοϓ ϓϩάϥϛϯάΨΠυ” ΑΓ ɹɹIN : ໿10ඵҎ಺ ɹɹOUT : 1ʙ15෼ఔͷ஗Ε ੍ݶ
  9. 32.

    ಛ௃ͱ੍ݶ ಛ௃: ɹ1. SuspendedɺNot Runningͷঢ়ଶͰ΋ݕ஌ಈ࡞ܧଓ ɹ2. লόοςϦʔফඅ ɹ3. ௥ՃσόΠεෆཁͰ೚ҙͷ஍఺Λొ࿥Մೳ ੍ݶ:

    ɹ1. ਫ਼౓ͷݶք : 100m୯Ґ ɹ2. ݕ஌λΠϛϯάͷ஗͞ : Outݕ஌͸1ʙ15෼ޙ ɹ3. ஍఺ొ࿥਺: 1ΞϓϦʹ͖ͭ20Օॴ·Ͱ
  10. 37.

    // γϯάϧτϯͷϚωʔδϟΫϥε // GeoFenceManager.swift import CoreLocation private let locationManager =

    CLLocationManager() override init() { super.init() self.locationManager.delegate = self // Ґஔ৘ใ࢖༻ڐՄ֬ೝ(Always) self.locationManager.requestAlwaysAuthorization() }
  11. 38.

    // γϯάϧτϯͷϚωʔδϟΫϥε // GeoFenceManager.swift import CoreLocation private let locationManager =

    CLLocationManager() override init() { super.init() self.locationManager.delegate = self // Ґஔ৘ใ࢖༻ڐՄ֬ೝ(Always) self.locationManager.requestAlwaysAuthorization() }
  12. 39.
  13. 41.

    // ؍ଌྖҬੜ੒ let coordinate = CLLocationCoordinate2DMake(35.658517,139.701334) let region = CLCircularRegion(center:

    coordinate, radius: 200, identifier: “ौ୩Ӻ”) // ؍ଌ։࢝ self.locationManager.startMonitoringForRegion(region)
  14. 46.

    // GeoFenceManager.swift // ྖҬ؍ଌΛऴྃ func stopMonitoringGeoFenceItem(geoFenceItem: GeoFenceItem) { for region

    in self.locationManager.monitoredRegions { if region.identifier == geoFenceItem.identifier { self.locationManager.stopMonitoringForRegion(region) } } }
  15. 58.

    ·ͱΊ ಛ௃: ɹ1. SuspendedɺNot Runningͷঢ়ଶͰ΋ݕ஌ಈ࡞ܧଓ ɹ2. লόοςϦʔফඅ ɹ3. ௥ՃσόΠεෆཁͰ೚ҙͷ஍఺Λొ࿥Մೳ ੍ݶ:

    ɹ1. ਫ਼౓ͷݶք : 100m୯Ґ ɹ2. ݕ஌λΠϛϯάͷ஗͞ : Outݕ஌͸1ʙ15෼ޙ ɹ3. ஍఺ొ࿥਺: 1ΞϓϦʹ͖ͭ20Օॴ·Ͱ
  16. 63.

    ࢀߟURL ɾҐஔ৘ใͱϚοϓ ϓϩάϥϛϯάΨΠυ https://developer.apple.com/jp/documentation/LocationAwarenessPG.pdf ɾCore Location Best Practices https://developer.apple.com/videos/play/wwdc2016/716/ ɾApple

    Sample Code: Regions: region monitoring, significant location changes, background location service, location service authorization https://developer.apple.com/library/ios/samplecode/Regions/Introduction/ Intro.html#//apple_ref/doc/uid/DTS40010726 ɾRegion Monitoring and iBeacon https://developer.apple.com/library/ios/documentation/UserExperience/ Conceptual/LocationAwarenessPG/RegionMonitoring/RegionMonitoring.html