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

Synchronized iPhones!

Tachibana Kaoru
September 01, 2018

Synchronized iPhones!

iOSDC 2018

Tachibana Kaoru

September 01, 2018
Tweet

More Decks by Tachibana Kaoru

Other Decks in Technology

Transcript

  1. About Me @TachibanaKaoru Freelance iOS Engineer iOSDC Core Staff (Track

    A) ϘϧμϦϯά޷͖ ࠓ೥ͷςʔϚɿཱྀΛ͠ͳ͕Β࢓ࣄΛ͢Δ όϦౡɺαϯτϦʔχౡɺόϯίΫɺϑΟϯϥϯυɺϊϧ΢Σʔ ͱ͖Ͳ͖φΨϊ 2018 ࢀՃத
  2. OK

  3. NG

  4. How to use CADisplayLink let displaylink = CADisplayLink(target: self, selector:

    #selector(drawSomething)) displaylink?.add(to: .current, forMode: RunLoop.Mode.default)
  5. iOS୺຤ͷ࣌ࠁ͋Θͤ NITZ GPS NTP iPhone ◦ ◦ ◦ iPad (with

    Mobile) ◦ ◦ ◦ iPad (without Mobile) × ◦ ◦ iPod touch × × ◦
  6. What is TAI? TAI : Temps Atomique International ʢϑϥϯεޠʣɺࠃࡍݪࢠ࣌ Le

    TAI est une échelle de temps-coordonnée définie dans un repère de référence géocentrique avec comme unité d'échelle la seconde du SI telle qu'elle est réalisée sur le géoïde en rotation ༁ɿTAI ͸, ճస͢ΔδΦΠυ্Ͱ࣮ݱ͞ΕΔ SI ͷඵΛ໨੝Γͷ୯Ґͱͨ͠, ஍৺࠲ඪܥͰఆٛ͞ΕΔ࠲ඪ࣌ͷ໨ ੝ΓͰ͋Δ ― CCDS ͷ੠໌ɺBIPM Com. Cons. Déf. Seconde, 1980, 9, S 15 ٴͼ Metrologia, 1981, 17, 70
  7. What is TAI? TAI ͸ɺճస͢ΔδΦΠυ্Ͱ࣮ݱ͞ΕΔ SI ͷඵΛ໨੝Γͷ୯Ґͱ͠ ͨɺ஍৺࠲ඪܥͰఆٛ͞ΕΔ࠲ඪ࣌ͷ໨੝ΓͰ͋Δɻ SIͷඵͱ͸ɺʮηγ΢Ϝ133ݪࢠͷجఈঢ়ଶͷ2ͭͷ௒ඍࡉߏ଄४ҐʢF =

    4, M = 0 ͓Αͼ F = 3, M = 0ʣؒͷભҠʹରԠ͢Δ์ࣹͷपظͷ 9 192 631 770 ഒͷܧଓ࣌ؒɻʯʢ1967೥੍ఆʣ 1967೥ΑΓલ͸ɺ̍೔ͷ௕͞Λ 86400 Ͱ෼ׂͨ͠΋ͷͰͨ͠ɻ
  8. What is UTC? UTC : Coordinated Universal Timeɺ ڠఆੈք࣌ ࠃࡍݪࢠ࣌

    (TAI) ʹ༝དྷ͢Δݪࢠ࣌ܥͷ࣌ࠁͰɺUT1ੈք࣌ʹಉௐ͢ΔΑ ͏ʹௐ੔͞Εͨج४࣌ࠁΛࢦ͢ɻ 1972೥͔Β࢖ΘΕ͍ͯΔɻ
  9. ఱจ͔࣌Βܭࢉͨ࣌͠ࠁ TAI UT1 ఱจ͔࣌Βܭࢉ ͨ࣌͠ࠁ x13 x13 x13 x13 x13

    X13 1೔ͷ௕͕͞13 SIඵͷ೔ 1೔ͷ௕͕͞13 SIඵͷ೔ 1೔ͷ௕͕͞16 SIඵͷ೔
  10. UTC TAI UT1 UTC x13 x13 X13+3 x13 x13 X13

    1೔ͷ௕͕͞13 SIඵͷ೔ 1೔ͷ௕͕͞13 SIඵͷ೔ 1೔ͷ௕͕͞16 SIඵͷ೔ ͏Δ͏ඵ
  11. Leap second in iOS and macOS લճͷ͏Δ͏ඵ͸ɺ2016/12/31 23:59:60 UTCͰͨ͠ɻ 2016/12/31

    23:59:59 UTC 2016/12/31 23:59:60 UTC 2017/01/01 00:00:00 UTC
  12. Leap second in iOS and macOS let calendar = Calendar(identifier:

    .gregorian) // 2016/12/31 23:59 var dateComp20162332235959 = DateComponents() dateComp20162332235959.calendar = calendar dateComp20162332235959.year = 2016 dateComp20162332235959.month = 12 dateComp20162332235959.day = 31 dateComp20162332235959.hour = 23 dateComp20162332235959.minute = 59 dateComp20162332235959.second = 59 dateComp20162332235959.date?.timeIntervalSince1970 // => 1483196399
  13. Leap second in iOS and macOS let calendar = Calendar(identifier:

    .gregorian) // 2016/12/31 23:60 var dateComp20162332235960 = DateComponents() dateComp20162332235960.calendar = calendar dateComp20162332235960.year = 2016 dateComp20162332235960.month = 12 dateComp20162332235960.day = 31 dateComp20162332235960.hour = 23 dateComp20162332235960.minute = 59 dateComp20162332235960.second = 60 dateComp20162332235960.date?.timeIntervalSince1970 // => 1483196400
  14. Leap second in iOS and macOS let calendar = Calendar(identifier:

    .gregorian) // 2017/01/01 00:00 var dateComp20170101000000 = DateComponents() dateComp20170101000000.calendar = calendar dateComp20170101000000.year = 2017 dateComp20170101000000.month = 1 dateComp20170101000000.day = 1 dateComp20170101000000.hour = 0 dateComp20170101000000.minute = 0 dateComp20170101000000.second = 0 dateComp20170101000000.date?.timeIntervalSince1970 // => 1483196400
  15. Leap second in iOS and macOS // 2016/12/31 23:59 dateComp20162332235959.date?.timeIntervalSince1970

    // => 1483196399 // 2016/12/31 23:60 dateComp20162332235960.date?.timeIntervalSince1970 // => 1483196400 // 2017/01/01 00:00 dateComp20170101000000.date?.timeIntervalSince1970 // => 1483196400 2016/12/31 23:60ͱ2017/01/01 00:00͸಺෦తʹ౳͍͠ɻ ʹɹ͏Δ͏ඵʹ͸ରԠ͍ͯ͠ͳ͍ɻ
  16. ඵͷ௕͞ ͏Δ͏ඵิਖ਼ ӡ༻ظؒ TAI SIඵʢݻఆʣ ͳ͠ 1970~ GPS Time SIඵʢݻఆʣ

    ͳ͠ 1980~ UTC SIඵʢݻఆʣ ͋Γ 1972~ چUTC มಈ ͳ͠ 1961~1971
  17. ௨৴࣌ͷ஗ԆΛফڈ͢Δ Peripheral Central 1 2 3 4 5 6 1.2

    2.6 3 2.6 1.4 3 + ( 2.6 - 1.4) / 2 = 3.6 3.0 0.4 1.4 2.4 3.4 4.4 5.4
  18. ௨৴࣌ͷ஗ԆΛফڈ͢Δ Peripheral Central 1 2 3 4 5 6 1.2

    2.6 3.6 > 3.0 3.0 0.4 1.4 2.4 3.4 4.4 5.4 3 2.6 1.4
  19. ௨৴࣌ͷ஗ԆΛফڈ͢Δ Peripheral Central 1 2 3 4 5 6 1.2

    2.6 3.6 > 3.0 3.6 0.4 1.4 2.4 3.4 4.4 5.4 3 2.6 1.4
  20. ௨৴࣌ͷ஗ԆΛফڈ͢Δ Peripheral Central 1 2 3 4 5 6 1.2

    2.6 3.6 > 3.0 3.6 1.0 2.0 3.0 4.0 5.0 6.0 3 2.6 1.4
  21. ௨৴࣌ͷ஗ԆΛফڈ͢Δ Peripheral Central 1 2 3 4 5 6 1.2

    2.6 3.6 4.0 4.6 1.0 2.0 3.0 4.0 5.0 6.0
  22. ௨৴࣌ͷ஗ԆΛফڈ͢Δ Peripheral Central 1 2 3 4 5 6 1.2

    2.6 3.6 4.0 4.6 5 4.6 4.0 1.0 2.0 3.0 4.0 5.0 6.0
  23. ௨৴࣌ͷ஗ԆΛফڈ͢Δ Peripheral Central 1 2 3 4 5 6 1.2

    2.6 3.6 4.0 4.6 5 + (4.6 - 4.0) / 2 = 5.3 5.6 1.0 2.0 3.0 4.0 5.0 6.0 5 4.6 4.0
  24. ௨৴࣌ͷ஗ԆΛফڈ͢Δ Peripheral Central 1 2 3 4 5 6 1.2

    2.6 3.6 4.0 4.6 5.3 < 5.6 5.6 1.0 2.0 3.0 4.0 5.0 6.0 5 4.6 4.0