HomeKit 2020

0d04162c7a3c2907c059a06dbcd23cf4?s=47 tokorom
September 19, 2020

HomeKit 2020

iOSDC Japan 2020 9/19 TrackA のセッション

0d04162c7a3c2907c059a06dbcd23cf4?s=128

tokorom

September 19, 2020
Tweet

Transcript

  1. ॴ༑ଠ:VUB5PLPSP J04UW04"QQ1SPHSBNNFS )PNF,JU J04%$+BQBO

  2. @tokorom tokorom Spinners Inc. ॴ ༑ଠ / Yuta Tokoro

  3. )PNF,JU֓ཁ )PNF,JUͱ͸

  4. )PNF,JU֓ཁ )PNF,JUશମ૾ w J1IPOFͳͲͷ"QQMF੡඼͔Β༷ʑͳσόΠε Λ؅ཧɾίϯτϩʔϧ͢ΔͨΊͷ࿮૊Έ )PNF,JU

  5. )PNF,JU֓ཁ )PNF,JU'SBNFXPSL w αʔυύʔςΟ੡ΞϓϦ͕ରԠ੡඼Λίϯτ ϩʔϧ͢ΔͨΊͷ'SBNFXPSL )PNF,JU 'SBNFXPSL

  6. )PNF,JU֓ཁ )PNF,JU"%, w )PNF,JUʹରԠσόΠεΛ։ൃ͢ΔͨΊͷΩ οτ )PNF,JU "%,

  7. )PNF,JU֓ཁ )"1 w "QQMF੡඼ͱ)PNF,JUରԠσόΠε͕૬ޓʹ ௨৴͢ΔͨΊͷϓϩτίϧ )PNF,JU "DDFTTPSZ 1SPUPDPM )"1

  8. "HFOEB w )PNF,JU'SBNFXPSLͬ͘͟Γೖ໳ w )PNF,JUͷ#SJEHFʹ͍ͭͯ w )PNFCSJEHFͰ)PNF,JUະରԠ੡඼Λ)PNF,JUରԠ w )PNF,JU"%,Ͱ࡞Δࣗ࡞ΞΫηαϦ

  9. "HFOEB w )PNF,JU'SBNFXPSLͬ͘͟Γೖ໳ w )PNF,JUͷ#SJEHFʹ͍ͭͯ w )PNFCSJEHFͰ)PNF,JUະରԠ੡඼Λ)PNF,JUରԠ w )PNF,JU"%,Ͱ࡞Δࣗ࡞ΞΫηαϦ

  10. )PNF,JU'SBNFXPSLͬ͘͟Γೖ໳ )PNF,JU'SBNFXPSLͰͰ͖Δ͜ͱ

  11. )PNF,JU'SBNFXPSLͬ͘͟Γೖ໳ )PNF,JU'SBNFXPSLͰͰ͖Δ͜ͱ

  12. )PNF,JU'SBNFXPSLͬ͘͟Γೖ໳ )PNF,JU'SBNFXPSLͰͰ͖Δ͜ͱ w ϗʔϜ΍ϧʔϜͳͲͷάϧʔϐϯάͷ؅ཧ w σόΠεͷ؅ཧͱૢ࡞ w σόΠεΛҰ౓ʹૢ࡞͢Δγʔϯͷ؅ཧ w ΦʔτϝʔγϣϯͷͨΊͷτϦΨʔͷ؅ཧ

    w ϗʔϜʹΞΫηεͰ͖ΔϢʔβʔͷ؅ཧ w ϗʔϜ΍σόΠεͷมߋݕ஌
  13. )PNF,JU'SBNFXPSLͬ͘͟Γೖ໳ ؅ཧཁૉͷߏ੒

  14. )PNF,JU'SBNFXPSLͬ͘͟Γೖ໳ )PNF,JUͷߏ੒

  15. )PNF,JU'SBNFXPSLͬ͘͟Γೖ໳ ిٿΛ఺౮ͤ͞Δίʔυ let power = home .servicesWithTypes([HMServiceTypeLightbulb])? .first? .characteristics .filter

    { $0.characteristicType == HMCharacteristicTypePowerState } .first power.writeValue(true) { error in }
  16. )PNF,JU'SBNFXPSLͬ͘͟Γೖ໳ αϙʔτ͍ͯ͠ΔΩϟϥΫλʔ let power = home .servicesWithTypes([HMServiceTypeLightbulb])? .first? .characteristics .filter

    { $0.characteristicType == HMCharacteristicTypePowerState } .first power.writeValue(true) { error in }
  17. )PNF,JU'SBNFXPSLͬ͘͟Γೖ໳ αϙʔτ͍ͯ͠ΔΩϟϥΫλʔ

  18. )PNF,JU'SBNFXPSLͬ͘͟Γೖ໳ Ӆ͠ΩϟϥΫλʔΛࢀর͢Δ &MHBUP&WF8FBUIFS8JSFMFTT0VUEPPS4FOTPS

  19. )PNF,JU'SBNFXPSLͬ͘͟Γೖ໳ Ӆ͠ΩϟϥΫλʔΛࢀর͢Δ w ؾԹ w ࣪౓ w ؾѹ)PNF,JUະαϙʔτͷΩϟϥΫλʔʂ

  20. )PNF,JU'SBNFXPSLͬ͘͟Γೖ໳ Ӆ͠ΩϟϥΫλʔΛࢀর͢Δ let power = home .servicesWithTypes([HMServiceTypeLightbulb])? .first? .characteristics .filter

    { $0.characteristicType == HMCharacteristicTypePowerState } .first power.writeValue(true) { error in }
  21. )PNF,JU'SBNFXPSLͬ͘͟Γೖ໳ Ӆ͠ΩϟϥΫλʔΛࢀর͢Δ let airPressure = home .servicesWithTypes(["E863F00A-079E-48FF-8F27-9C2605A29F52"])? .first? .characteristics .filter

    { $0.characteristicType == "E863F10F-079E-48FF-8F27-9C2605A29F52" } .first airPressure.readValue { error in let value = airPressure.value as? Float }
  22. )PNF,JU'SBNFXPSLͬ͘͟Γೖ໳ Ӆ͠ΩϟϥΫλʔΛࢀর͢Δ for characteristic in service.characteristics { print("ID: \(characteristic.characteristicType)”) print("આ໌:

    \(characteristic.metadata?.manufacturerDescription ?? "")") }
  23. )PNF,JU'SBNFXPSLͬ͘͟Γೖ໳ ).$BNFSB7JFX

  24. )PNF,JUͰͰ͖Δ͜ͱ۩ମྫ ଞϓϥοτϑΥʔϜΑΓࡉ΍͔ͳઃఆ w ΫϦεϚεϥΠτΛʮ೔ͷೖʯʹ఺౮͢Δ w Ոʹ୭΋͍ͳ͘ͳͬͨΒશͯͷిؾΛফ౮ͯ͠ώʔλʔΛࢭΊΔ w ࣗಈ఺౮ͨ͠ϥΠτΛඵޙʹফ౮͢Δ w ೔தͰτΠϨ͕े෼໌Δ͚Ε͹ࣗಈ఺౮͠ͳ͍

  25. "HFOEB w )PNF,JU'SBNFXPSLͬ͘͟Γೖ໳ w )PNF,JUͷ#SJEHFʹ͍ͭͯ w )PNFCSJEHFͰ)PNF,JUະରԠ੡඼Λ)PNF,JUରԠ w )PNF,JU"%,Ͱ࡞Δࣗ࡞ΞΫηαϦ

  26. )PNF,JUͷ#SJEHFʹ͍ͭͯ )VFͷྫ

  27. )PNF,JUͷ#SJEHFʹ͍ͭͯ )VFͷྫ )PNF,JUະରԠʂʁ

  28. )PNF,JUͷ#SJEHFʹ͍ͭͯ )VFͷྫ )VF#SJEHF

  29. )PNF,JUͷ#SJEHFʹ͍ͭͯ )VFͷྫ )VF#SJEHF

  30. )PNF,JUͷ#SJEHFʹ͍ͭͯ )PNFCSJEHF IUUQTIPNFCSJEHFJP

  31. )PNF,JUͷ#SJEHFʹ͍ͭͯ )VFͷྫ )PNFCSJEHF " # $ %

  32. "HFOEB w )PNF,JU'SBNFXPSLͬ͘͟Γೖ໳ w )PNF,JUͷ#SJEHFʹ͍ͭͯ w )PNFCSJEHFͰ)PNF,JUະରԠ੡඼Λ)PNF,JUରԠ w )PNF,JU"%,Ͱ࡞Δࣗ࡞ΞΫηαϦ

  33. )PNFCSJEHF ରԠσόΠεͷ۩ମྫ ϧϯό #SPBEMJOL3.NJOJ ʢ੺֎ઢϦϞίϯʣ 4&4".& ʢεϚʔτϩοΫʣ Χϝϥ

  34. )PNFCSJEHF ࣗ୐Ͱ)PNFCSJEHFΛ࢖͏ʹ͸ " # $ %

  35. )PNFCSJEHF ࣗ୐Ͱ)PNFCSJEHFΛ࢖͏ʹ͸ " # $ % IUUQTIPNFCSJEHFJP

  36. )PNFCSJEHF )PNFCSJEHFΛ)PNFʹ௥Ճ

  37. )PNFCSJEHF ϓϥάΠϯΛࣗ࡞ IUUQTHJUIVCDPNIPNFCSJEHFIPNFCSJEHFQMVHJOUFNQMBUF

  38. "HFOEB w )PNF,JU'SBNFXPSLͬ͘͟Γೖ໳ w )PNF,JUͷ#SJEHFʹ͍ͭͯ w )PNFCSJEHFͰ)PNF,JUະରԠ੡඼Λ)PNF,JUରԠ w )PNF,JU"%,Ͱ࡞Δࣗ࡞ΞΫηαϦ

  39. )PNF,JU"%, ֓ཁ w )PNF,JU"DDFTTPSZ%FWFMPQNFOU,JU w ΞΫηαϦʔϝʔΧʔ͕)PNF,JUରԠσόΠεΛ։ൃ͢ΔͨΊͷΩοτ w ೥݄ʹΦʔϓϯιʔε൛͕ϦϦʔε w झຯͰͳΒࣗ༝ʹ։ൃͯ͠0,

  40. )PNF,JU"%, )PNFCSJEHFͱͷҧ͍ )PNFCSJEHF # $ % "

  41. )PNF,JU"%, )PNFCSJEHFͱͷҧ͍ "%, # $ % " "%, "%, "%,

  42. )PNF,JU"%, ࣗ෼ͰΞΫηαϦʔΛ࡞Δ IUUQTHJUIVCDPNBQQMF)PNF,JU"%,

  43. )PNF,JU"%, ࣗ෼ͰΞΫηαϦʔΛ࡞Δ $ brew install [υΩϡϝϯτʹॻ͔Ε͍ͯΔ΋ͷ͍͔ͭ͘] $ make all $

    ./Output/লུ/Debug/IP/Applications/Lightbulb.OpenSSL
  44. )PNF,JU"%, ࣗ෼ͰΞΫηαϦʔΛ࡞Δ Info [com.apple.mfi.HomeKit.Core:AccessoryServer] Accessory server starting.

  45. )PNF,JU"%, ࣗ෼ͰΞΫηαϦʔΛ࡞Δ

  46. )PNF,JU"%, ࣗ෼ͰΞΫηαϦʔΛ࡞Δ Info HandleLightBulbOnWrite: true ... Info HandleLightBulbOnWrite: false

  47. )PNF,JU"%, ࣗ෼ͰΞΫηαϦʔΛ࡞Δ lightbulb_slack/Applications/Lightbulb/App.c #include <stdlib.h> HAPError HandleLightBulbOnWrite( // ... if

    (value) { system("./handleLightBulbOn"); } // ... }
  48. )PNF,JU"%, ࣗ෼ͰΞΫηαϦʔΛ࡞Δ #!/usr/bin/swift import Foundation let slackURL = URL(string: "Incoming

    Webhook URL") var request = URLRequest(url: slackURL!) request.httpMethod = "POST" request.setValue("application/json", forHTTPHeaderField: "Content-type") let message = "ϥΠτ͕఺౮" let postData = "{\"text\": \"\(message)\"}".data(using: .utf8) request.httpBody = postData let semaphore = DispatchSemaphore(value: 0) let session = URLSession(configuration: URLSessionConfiguration.default) let task = session.dataTask(with: request) { _, _, _ in semaphore.signal() } task.resume() semaphore.wait()
  49. )PNF,JU"%, ࣗ෼ͰΞΫηαϦʔΛ࡞Δ

  50. .PSF*OGPSNBUJPO w J041SPHSBNNJOH w Ξοϓϧͷ)PNF1PEͱ)PNF,JUٕज़ຊ IUUQTQFBLTDDCPPLTJ04 IUUQTCPPUIQNKBJUFNT