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

HomeKit 2020

tokorom
September 19, 2020

HomeKit 2020

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

tokorom

September 19, 2020
Tweet

More Decks by tokorom

Other Decks in Programming

Transcript

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

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

    { $0.characteristicType == HMCharacteristicTypePowerState } .first power.writeValue(true) { error in }
  3. )PNF,JU'SBNFXPSLͬ͘͟Γೖ໳ Ӆ͠ΩϟϥΫλʔΛࢀর͢Δ let power = home .servicesWithTypes([HMServiceTypeLightbulb])? .first? .characteristics .filter

    { $0.characteristicType == HMCharacteristicTypePowerState } .first power.writeValue(true) { error in }
  4. )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 }
  5. )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()