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

SwiftでのGeoFence機能実装

satoshi0212
August 20, 2016
10k

 SwiftでのGeoFence機能実装

satoshi0212

August 20, 2016
Tweet

Transcript

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

    MPC Hackathon TMCN৆ ɹHack Cars Days 2015 χϑςΟ৆ ɹMUSICIANS HACKATHON 2015 ༏ल৆ ɹɹͳͲ
  2. 1 Standard Location 2 Background Location Session 3 Beacon Ranging

    4 Geographical Region Monitoring 5 Visit Monitoring 6 Significant Location Change Monitoring Ґஔ৘ใ࣮૷ํ๏ͷ؆୯ͳ·ͱΊ
  3. 1 Standard Location ඪ४Ґஔ৘ใ 2 Background Location Session όοΫάϥ΢ϯυ ͰͷҐஔ৘ใ

    3 Beacon Ranging ϏʔίϯྖҬ؍ଌ 4 Geographical Region Monitoring ஍ཧతྖҬ؍ଌ 5 Visit Monitoring ๚໰ઌ௥੻ 6 Significant Location Change Monitoring େ෯มߋҐஔ৘ใ Ґஔ৘ใ࣮૷ํ๏ͷ؆୯ͳ·ͱΊ
  4. 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. 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. 1. ਫ਼౓ͷݶք : 100m୯Ґ 2. ݕ஌λΠϛϯάͷ஗͞ : Outݕ஌͸1ʙ15෼ޙ ʮϢʔβͷҐஔ͕ྖҬͷڥքઢΛԣஅ͠ɺ͜ͷڥքઢ͔Β ࠷খڑ཭͚ͩ཭Ε͔ͯΒɺ͜ͷҐஔΛগͳ͘ͱ΋20ඵؒอ

    ࣋͠ͳ͍ͱɺ௨஌͸ใࠂ͞Ε·ͤΜɻʯ “Ґஔ৘ใͱϚοϓ ϓϩάϥϛϯάΨΠυ” ΑΓ ɹɹIN : ໿10ඵҎ಺ ɹɹOUT : 1ʙ15෼ఔͷ஗Ε ੍ݶ
  7. ಛ௃ͱ੍ݶ ಛ௃: ɹ1. SuspendedɺNot Runningͷঢ়ଶͰ΋ݕ஌ಈ࡞ܧଓ ɹ2. লόοςϦʔফඅ ɹ3. ௥ՃσόΠεෆཁͰ೚ҙͷ஍఺Λొ࿥Մೳ ੍ݶ:

    ɹ1. ਫ਼౓ͷݶք : 100m୯Ґ ɹ2. ݕ஌λΠϛϯάͷ஗͞ : Outݕ஌͸1ʙ15෼ޙ ɹ3. ஍఺ొ࿥਺: 1ΞϓϦʹ͖ͭ20Օॴ·Ͱ
  8. // γϯάϧτϯͷϚωʔδϟΫϥε // GeoFenceManager.swift import CoreLocation private let locationManager =

    CLLocationManager() override init() { super.init() self.locationManager.delegate = self // Ґஔ৘ใ࢖༻ڐՄ֬ೝ(Always) self.locationManager.requestAlwaysAuthorization() }
  9. // γϯάϧτϯͷϚωʔδϟΫϥε // GeoFenceManager.swift import CoreLocation private let locationManager =

    CLLocationManager() override init() { super.init() self.locationManager.delegate = self // Ґஔ৘ใ࢖༻ڐՄ֬ೝ(Always) self.locationManager.requestAlwaysAuthorization() }
  10. // ؍ଌྖҬੜ੒ let coordinate = CLLocationCoordinate2DMake(35.658517,139.701334) let region = CLCircularRegion(center:

    coordinate, radius: 200, identifier: “ौ୩Ӻ”) // ؍ଌ։࢝ self.locationManager.startMonitoringForRegion(region)
  11. // GeoFenceManager.swift // ྖҬ؍ଌΛऴྃ func stopMonitoringGeoFenceItem(geoFenceItem: GeoFenceItem) { for region

    in self.locationManager.monitoredRegions { if region.identifier == geoFenceItem.identifier { self.locationManager.stopMonitoringForRegion(region) } } }
  12. ·ͱΊ ಛ௃: ɹ1. SuspendedɺNot Runningͷঢ়ଶͰ΋ݕ஌ಈ࡞ܧଓ ɹ2. লόοςϦʔফඅ ɹ3. ௥ՃσόΠεෆཁͰ೚ҙͷ஍఺Λొ࿥Մೳ ੍ݶ:

    ɹ1. ਫ਼౓ͷݶք : 100m୯Ґ ɹ2. ݕ஌λΠϛϯάͷ஗͞ : Outݕ஌͸1ʙ15෼ޙ ɹ3. ஍఺ొ࿥਺: 1ΞϓϦʹ͖ͭ20Օॴ·Ͱ
  13. ࢀߟ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