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

CoreMotionを使って気づいたこととiOS11での新機能

 CoreMotionを使って気づいたこととiOS11での新機能

#potatotips

potatotips #42 (iOS/Android開発Tips共有会) - connpass
https://potatotips.connpass.com/event/60015/

Tatsuya Tanaka

July 25, 2017
Tweet

More Decks by Tatsuya Tanaka

Other Decks in Technology

Transcript

  1. • Yahoo!৐׵Ҋ಺ • iOSΞϓϦΤϯδχΞ • 2016೥৽ଔ • GitHub: @tattn •

    Qiita: @tattn • Twitter: @tanakasan2525 ాத ୡ໵ (@tattn)
  2. CoreMotion iPhone 5sҎ߱ʹ౥ࡌͷ
 ίϓϩηοα (M7Ҏ߱) Ͱେ෯ػೳڧԽ What's New in Core

    Motion https://developer.apple.com/videos/play/wwdc2015/705/ ←Ճ଎౓ηϯα ←δϟΠϩηϯα ←࣓ؾηϯα ←ߴ౓ηϯα
  3. ଌఆͰ͖Δ͜ͱͷ͢΂ͯ Ճ଎౓ηϯα δϟΠϩηϯα ࣓ؾηϯα ߴ౓ηϯα • ୺຤ͷ޲͖ (ճస) • (୺຤ʹର͢Δ)ॏྗͷํ޲

    • ୺຤ͷՃ଎౓(ॏྗແࢹ) • ֤ํ޲ͷ࣓ଋີ౓ • า਺ • า͍ͨڑ཭ (ਪఆ) • ฏۉ/ݱࡏͷา͘଎͞ [m/s] • Ұඵؒͷา਺ [า਺/s] • า͍ͯొͬͨ֊਺ (ਪఆ) • (ଌఆ͔ͯ͠Βͷ)૬ରߴ౓ • ؾѹ • ׆ಈঢ়ଶ 
 (ఀࢭ/ెา/૸Δ/ࣗಈं/
 ࣗసं)
  4. ύλʔϯ1 - ఆظऔಘ manager.deviceMotion?.rotationRate motionActivityManager.startActivityUpdates(to: .init()) { activity in guard

    let activity = activity else { return } if activity.stationary { print("ࢭ·ͬͯΔΑ") } if activity.cycling { print("νϟϦͰདྷͨ") } } ෼͔Γ΍͍͢☺औಘํ๏
  5. ύλʔϯ2 - ظؒͰऔಘ let now = Date() let dayBeforeYesterDay =

    now.addingTimeInterval(-60 * 60 * 24 * 2) pedometer.queryPedometerData(from: dayBeforeYesterDay, to: now) { data, error in guard let data = data, error == nil else { return } print(data.distance ?? 0) print(data.numberOfSteps) print(data.floorsAscended ?? 0) } ෼͔Γ΍͍͢☺औಘํ๏
  6. I/F͕ͨ·ʹ΍Δؾͳ͍ @available(iOS 9.0, *) open class CMSensorDataList : NSObject, NSFastEnumeration

    { } Swift͔Β࢖͍ʹ͍͘ protocol NSFastEnumeration { func countByEnumerating( with state: UnsafeMutablePointer<NSFastEnumerationState>, objects buffer: AutoreleasingUnsafeMutablePointer<AnyObject?>!, count len: Int) -> Int }
  7. I/F͕ͨ·ʹ΍Δؾͳ͍ @available(iOS 9.0, *) open class CMSensorDataList : NSObject, NSFastEnumeration

    { } extension CMSensorDataList: Sequence { public func makeIterator() -> NSFastEnumerationIterator { return NSFastEnumerationIterator(self) } } Tips: ΍ΔؾΛ࣮૷ ͍ͭ΋ͷ for-in, map ͳͲ
  8. ڐՄঢ়ଶΛࣄલʹऔಘՄೳʹ ࠓ·Ͱ iOS 11͔Β pedometer.queryPedometerData(from: now, to: now) { (data,

    error) in if let code = error?._code, code == Int(CMErrorMotionActivityNotAuthorized.rawValue) { // ະڐՄ } if CMPedometer.isStepCountingAvailable() { switch CMPedometer.authorizationStatus() { case .notDetermined: break case .restricted: break case .denied: break case .authorized: break } }
  9. Ճ଎౓ͷه࿥͕Մೳʹ (7/7+ on iOS11) CMSensorRecoder • ه࿥࣌ؒΛࢦఆͯ͠ه࿥։࢝ (࠷େ36h) • όοΫάϥ΢ϯυͰ50HzͰܭଌ

    (ΞϓϦΛऴྃͯ͠΋) • ࠷େ3೔ؒͷه࿥ΛऔಘՄೳ • ࠶౓ه࿥Λ։࢝ͨ͠Γ
 ଞͷΞϓϦ͕ه࿥Λ։࢝͢Δͱ࣌ؒΛԆ௕Մೳ
  10. Ճ଎౓ͷه࿥͕Մೳʹ (7/7+ on iOS11) CMSensorRecoder • Apple Watch • Apple

    Watch Series 1 • Apple Watch Series 2 • iPhone 7/7 Plus (iOS 11) ॳΊͯiPhoneͰ࢖༻Մೳʹ