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

External Accessory入門

Trickart
September 02, 2023

External Accessory入門

iOSDC2023発表資料

Trickart

September 02, 2023
Tweet

More Decks by Trickart

Other Decks in Technology

Transcript

  1. ૣ଎࡞Δ ίʔυΛॻ͍͍ͯ͘&"4FTTJPO w ௨৴ηογϣϯͷ&"4FTTJPOΛ։࢝͢Δ w JOJUʹ௨৴͍ͨ͠&""DDFTTPSZͱQSPUPDPM4USJOHΛ౉͢ for accessory in EAAccessoryManager.shared().connectedAccessories

    { guard accessory.protocolStrings.contains("jp.star-m.starpro") else { continue } let session = EASession(accessory: accessory, forProtocol: "jp.star-m.starpro") }
  2. ૣ଎࡞Δ ίʔυΛॻ͍͍ͯ͘&"4FTTJPO w &"4FTTJPO͸JOQVU4USFBNͱPVUQVU4USFBNΛ͍࣋ͬͯΔ w JOQVU4USFBN͔ΒσʔλΛಡΈग़ͯ͠ड৴ w PVUQVU4USFBNʹσʔλΛॻ͖ࠐΜͰૹ৴ w 4USFBNʹEFMFHBUFΛ౉ͯ͠3VO-PPQʹεέδϡʔϧͯ͠։͘

    guard let session = EASession(accessory: accessory, forProtocol: protocolString), let outputStream = session.outputStream else { return nil } outputStream.delegate = self outputStream.schedule(in: .current, forMode: .default) outputStream.open()
  3. ૣ଎࡞Δ ίʔυΛॻ͍͍ͯ͘ /4 4USFBN w 4USFBN͸ੲͳ͕Βͷ/44USFBN w 0VUQVU4USFBNʹ6OTBGF1PJOUFS6*OUͱͯ͠όΠτྻΛ౉͢ // "0"ͱ͚ͩҹࣈͯ͠վߦ͠ϖʔύʔΧοτ͢Δ

    var bytes: [UInt8] = [0x30, 0x0e, 0x0a, 0x1b, 0x64, 0x03] let length = outputStream.write(&bytes, maxLength: bytes.count) if length < 0 { print("error!") } else if length == 0 { print("full.") } else { if length != bytes.count { print("write data was split.") } // ॻ͖ࠐΜͩσʔλͷ࡟আ bytes = Array(bytes.dropFirst(length)) }
  4. ૣ଎࡞Δ ίʔυΛॻ͍͍ͯ͘จࣈҹ࡮ w ελʔਫ਼ີ੡ϓϦϯλʔ͸4UBS13/5ͱ͍͏ϑΥʔϚοτ w 4IJGU+*4ͷςΩετͱ"4$**ͷ੍ޚจࣈͰఆٛ͞Ε੍ͨޚίϚϯυ͔ΒͳΔ w ೔ຊޠͷςΩετ΋ҹ࡮Մೳʂ let hello

    = Array("͜Μʹͪ͸ɺiOSDC 2023!".data(using: .shiftJIS)!) var bytes: [UInt8] = hello + [0x0e, 0x0a, 0x1b, 0x64, 0x03] let length = outputStream.write(&bytes, maxLength: bytes.count)