Share
Embed
AccessorySetupKitで実現するシームレスなペアリング体験 / Seamless pairing with AccessorySetupKit
iOSDC Japan 2025 Day0 Track D 18:30 -
https://fortee.jp/iosdc-japan-2025/proposal/32da7be3-c77e-409c-b30d-f7322e5cd88e
nekowen
September 19, 2025
Annual Pro sale · Save $30
Have presentations of your own?
Share with private links, password protection, and more control over your work.
Transcript
77 slides
-
Bluetooth Classic(BR/EDR/HS) Bluetooth Low Energy(BLE) ɾैདྷ͔Β͋Δඪ४తͳن֨ ɾ࠷େ 3Mbps ͷσʔλసૹ ɾϖΞϦϯάඞਢ
ɾফඅిྗ͕ߴ͍ ɾBluetooth 4.0 ͔Βొ ɾ࠷େ 1 - 2Mbps ͷσʔλసૹ ɾϖΞϦϯάҙ ɾফඅిྗ͕͍ Bluetooth ʹ͍ͭͯ -
Ϣʔβʔઢ • ڐՄ͢ΔͨΊͷஅίετ͕͔͔Δ ։ൃऀઢ • ΞϥʔτΛग़͢λΠϛϯά͕͍͠ • ڐՄ͞Εͳ͔ͬͨ࣌ͷϋϯυϦϯά͕ඞཁ • ઃఆʹભҠͤ͞Δʁ
Core Bluetooth API ͷར༻ʹϢʔβʔڐՄ͕ඞཁ -
AccessorySetupKit ͱԿ͔ • iOS18 ͔Βొͨ͠ϑϨʔϜϫʔΫ • ϓϥΠόγʔΛอͬͨ·· Bluetooth/WiFi Λར༻ ͨ͠σόΠεͷݕग़ɾϖΞϦϯάॲཧΛ୲͏
• ΞΫηαϦ͕Ճ͞ΕͨޙɺCore Bluetooth ଓॲཧͷҾ͖ܧ͕͗Մೳ ref: https://developer.apple.com/videos/play/wwdc2024/10203/ -
ଓϑϩʔ͕౷Ұ͞ΕΔ • σόΠεͱͷଓʹඞཁͳॲཧɾUI ΛϑϨʔϜϫʔΫ ଆ͕ఏڙ͢Δ • Bluetooth LE σόΠεͷεΩϟϯ •
ݟ͔ͭͬͨσόΠεͷબ • (PIN ίʔυ͕ඞཁͳ߹) PIN ίʔυͷೖྗ • ϖΞϦϯάɾϘϯσΟϯά -
ઃఆΞϓϦͰʮΞΫηαϦʯͱͯ͠ཧՄೳ • ηοτΞοϓ͞ΕͨσόΠε ʮΞΫηαϦʯͱͯ͠ɺiOS ͷ ઃఆΞϓϦ͔ΒཧՄೳ • ΞϓϦ͔Β໊ɾը૾Λ͢ͱɺ ઃఆΞϓϦ͔Βݟ͑ΔΑ͏ʹͳΔ •
Bluetooth ໊͔ΒΛਪଌ͢Δඞཁ ͕ͳ͘ɺҰྎવ -
AccessorySetupKit ͰεΩϟϯͰ͖Δ݅ • ҎԼͷ͍ͣΕ͔ͷ AD Structure ΛΞυόλΠζ͢Δ͜ͱ • Service UUID
• Company ID (Manufacture Speci f ic Data) -
ࣗ͜͜ʹ͍ΔΑʂ Service UUID: xxxx-xxxx Local Name: BLE-Demo Manufacture Speci f
ic Data: … ΞυόλΠζͱ ଓରͷσόΠεͩͳʂϤγʂ -
AccessorySetupKit ΛͬͨϖΞϦϯάखॱ 1. Info.plist ͷઃఆ 2. ASAccessorySession ͷ activate ϝιουͰΠϕϯτͷ
ϋϯυϦϯάΛ࣮ 3. ଓ͢ΔσόΠεใΛ ASDiscoveryDescriptor ʹࢦఆ 4. showPicker ϝιουΛݺͼग़͢ -
AccessorySetupKit ΛͬͨϖΞϦϯάखॱ 1. Info.plist ͷઃఆ 2. ASAccessorySession ͷ activate ϝιουͰΠϕϯτͷ
ϋϯυϦϯάΛ࣮ 3. ଓ͢ΔσόΠεใΛ ASDiscoveryDescriptor ʹࢦఆ 4. showPicker ϝιουΛݺͼग़͢ -
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/
PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>NSAccessorySetupKitSupports</key> <array> <string>Bluetooth</string> </array> <key>NSAccessorySetupBluetoothCompanyIdentifiers</key> <array> <string>XXXX</string> </array> <key>NSAccessorySetupBluetoothServices</key> <array> <string>181C</string> </array> <key>NSAccessorySetupBluetoothNames</key> <array> <string>BLE</string> </array> </dict> </plist> -
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/
PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>NSAccessorySetupKitSupports</key> <array> <string>Bluetooth</string> </array> <key>NSAccessorySetupBluetoothCompanyIdentifiers</key> <array> <string>XXXX</string> </array> <key>NSAccessorySetupBluetoothServices</key> <array> <string>181C</string> </array> <key>NSAccessorySetupBluetoothNames</key> <array> <string>BLE</string> </array> </dict> </plist> -
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/
PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>NSAccessorySetupKitSupports</key> <array> <string>Bluetooth</string> </array> <key>NSAccessorySetupBluetoothCompanyIdentifiers</key> <array> <string>XXXX</string> </array> <key>NSAccessorySetupBluetoothServices</key> <array> <string>181C</string> </array> <key>NSAccessorySetupBluetoothNames</key> <array> <string>BLE</string> </array> </dict> </plist> Bluetooth SIGͷϝϯόʔاۀʹׂΓͯΒΕΔݻ༗൪߸(ҙ) -
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/
PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>NSAccessorySetupKitSupports</key> <array> <string>Bluetooth</string> </array> <key>NSAccessorySetupBluetoothCompanyIdentifiers</key> <array> <string>XXXX</string> </array> <key>NSAccessorySetupBluetoothServices</key> <array> <string>181C</string> </array> <key>NSAccessorySetupBluetoothNames</key> <array> <string>BLE</string> </array> </dict> </plist> ΞυόλΠζ͞ΕΔService UUID(ॖUUIDՄ) -
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/
PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>NSAccessorySetupKitSupports</key> <array> <string>Bluetooth</string> </array> <key>NSAccessorySetupBluetoothCompanyIdentifiers</key> <array> <string>XXXX</string> </array> <key>NSAccessorySetupBluetoothServices</key> <array> <string>181C</string> </array> <key>NSAccessorySetupBluetoothNames</key> <array> <string>BLE</string> </array> </dict> </plist> Bluetooth໊Λࢦఆ ෦Ұக -
AccessorySetupKit ΛͬͨϖΞϦϯάखॱ 1. Info.plist ͷઃఆ 2. ASAccessorySession ͷ activate ϝιουͰΠϕϯτͷ
ϋϯυϦϯάΛ࣮ 3. ଓ͢ΔσόΠεใΛ ASDiscoveryDescriptor ʹࢦఆ 4. showPicker ϝιουΛݺͼग़͢ -
// MARK: - Accessory Setup private let session = ASAccessorySession()
private var currentAccessory: ASAccessory? // MARK: - AccessorySession session.activate(on: DispatchQueue.main) { [weak self] (event: ASAccessoryEvent) in guard let self else { return } switch event.eventType { case .activated: if let accessory = session.accessories.first { // ͢ͰʹηοτΞοϓࡁΈͰ͋ΕɺͦͷΞΫηαϦΛͬͯଓॲཧΛߦ͏ self.currentAccessory = accessory self.handleAccessoryAdded(accessory) } case .accessoryAdded: // ΞΫηαϦ͕Ճ͞Εͨ(ηοτΞοϓ͞Εͨ) self.currentAccessory = event.accessory case .pickerDidDismiss: // ϐοΧʔ͕ด͡ΒΕͨ guard let currentAccessory else { return } handleAccessoryAdded(currentAccessory) self.currentAccessory = nil case .pickerSetupFailed: // ԿΒ͔ͷཧ༝ʹΑΓηοτΞοϓʹࣦഊͨ͠(ύείʔυͷෆҰகͳͲ) ... } } -
// MARK: - Accessory Setup private let session = ASAccessorySession()
private var currentAccessory: ASAccessory? // MARK: - AccessorySession session.activate(on: DispatchQueue.main) { [weak self] (event: ASAccessoryEvent) in guard let self else { return } switch event.eventType { case .activated: if let accessory = session.accessories.first { // ͢ͰʹηοτΞοϓࡁΈͰ͋ΕɺͦͷΞΫηαϦΛͬͯଓॲཧΛߦ͏ self.currentAccessory = accessory self.handleAccessoryAdded(accessory) } case .accessoryAdded: // ΞΫηαϦ͕Ճ͞Εͨ(ηοτΞοϓ͞Εͨ) self.currentAccessory = event.accessory case .pickerDidDismiss: // ϐοΧʔ͕ด͡ΒΕͨ guard let currentAccessory else { return } handleAccessoryAdded(currentAccessory) self.currentAccessory = nil case .pickerSetupFailed: // ԿΒ͔ͷཧ༝ʹΑΓηοτΞοϓʹࣦഊͨ͠(ύείʔυͷෆҰகͳͲ) ... } } activateϝιουΛݺΜͩ࣌ɺ࠷ॳʹݺΕΔ -
// MARK: - Accessory Setup private let session = ASAccessorySession()
private var currentAccessory: ASAccessory? // MARK: - AccessorySession session.activate(on: DispatchQueue.main) { [weak self] (event: ASAccessoryEvent) in guard let self else { return } switch event.eventType { case .activated: if let accessory = session.accessories.first { // ͢ͰʹηοτΞοϓࡁΈͰ͋ΕɺͦͷΞΫηαϦΛͬͯଓॲཧΛߦ͏ self.currentAccessory = accessory self.handleAccessoryAdded(accessory) } case .accessoryAdded: // ΞΫηαϦ͕Ճ͞Εͨ(ηοτΞοϓ͞Εͨ) self.currentAccessory = event.accessory case .pickerDidDismiss: // ϐοΧʔ͕ด͡ΒΕͨ guard let currentAccessory else { return } handleAccessoryAdded(currentAccessory) self.currentAccessory = nil case .pickerSetupFailed: // ԿΒ͔ͷཧ༝ʹΑΓηοτΞοϓʹࣦഊͨ͠(ύείʔυͷෆҰகͳͲ) ... } } ΞΫηαϦ͕Ճ͞ΕͨΒݱࡏͷΞΫηαϦΛอ࣋ ʢ͜ͷ࣌·ͩγʔτදࣔ͞Ε͍ͯΔ) -
// MARK: - Accessory Setup private let session = ASAccessorySession()
private var currentAccessory: ASAccessory? // MARK: - AccessorySession session.activate(on: DispatchQueue.main) { [weak self] (event: ASAccessoryEvent) in guard let self else { return } switch event.eventType { case .activated: if let accessory = session.accessories.first { // ͢ͰʹηοτΞοϓࡁΈͰ͋ΕɺͦͷΞΫηαϦΛͬͯଓॲཧΛߦ͏ self.currentAccessory = accessory self.handleAccessoryAdded(accessory) } case .accessoryAdded: // ΞΫηαϦ͕Ճ͞Εͨ(ηοτΞοϓ͞Εͨ) self.currentAccessory = event.accessory case .pickerDidDismiss: // ϐοΧʔ͕ด͡ΒΕͨ guard let currentAccessory else { return } handleAccessoryAdded(currentAccessory) self.currentAccessory = nil case .pickerSetupFailed: // ԿΒ͔ͷཧ༝ʹΑΓηοτΞοϓʹࣦഊͨ͠(ύείʔυͷෆҰகͳͲ) ... } } γʔτ͕ด͡ΒΕͨͷͰଓॲཧΛߦ͏ -
// MARK: - CoreBluetooth private var central: CBCentralManager? // AccessorySetupKit
ͰΞΫηαϦ͕Ճ͞Εͨ࣌ʹݺΕΔϝιου private func handleAccessoryAdded(_ accessory: ASAccessory) { // Bluetooth IDΛऔಘ guard let bluetoothIdentifier = accessory.bluetoothIdentifier else { return } // CBCentralManager͕ະॳظԽͳΒॳظԽ͢Δ if central == nil { central = CBCentralManager(delegate: self, queue: nil) } // Bluetooth ID͔ΒCBPeripheralΛऔಘ͢Δ let peripherals = central?.retrievePeripherals(withIdentifiers: [bluetoothIdentifier]) // ֘ͷPeripheral͕ଘࡏ͍ͯ͠Εଓ͢Δ if let peripheral = peripherals?.first { bleConnect(peripheral) } } -
// MARK: - CoreBluetooth private var central: CBCentralManager? // AccessorySetupKit
ͰΞΫηαϦ͕Ճ͞Εͨ࣌ʹݺΕΔϝιου private func handleAccessoryAdded(_ accessory: ASAccessory) { // Bluetooth IDΛऔಘ guard let bluetoothIdentifier = accessory.bluetoothIdentifier else { return } // CBCentralManager͕ະॳظԽͳΒॳظԽ͢Δ if central == nil { central = CBCentralManager(delegate: self, queue: nil) } // Bluetooth ID͔ΒCBPeripheralΛऔಘ͢Δ let peripherals = central?.retrievePeripherals(withIdentifiers: [bluetoothIdentifier]) // ֘ͷPeripheral͕ଘࡏ͍ͯ͠Εଓ͢Δ if let peripheral = peripherals?.first { bleConnect(peripheral) } } -
// MARK: - CoreBluetooth private var central: CBCentralManager? // AccessorySetupKit
ͰΞΫηαϦ͕Ճ͞Εͨ࣌ʹݺΕΔϝιου private func handleAccessoryAdded(_ accessory: ASAccessory) { // Bluetooth IDΛऔಘ guard let bluetoothIdentifier = accessory.bluetoothIdentifier else { return } // CBCentralManager͕ະॳظԽͳΒॳظԽ͢Δ if central == nil { central = CBCentralManager(delegate: self, queue: nil) } // Bluetooth ID͔ΒCBPeripheralΛऔಘ͢Δ let peripherals = central?.retrievePeripherals(withIdentifiers: [bluetoothIdentifier]) // ֘ͷPeripheral͕ଘࡏ͍ͯ͠Εଓ͢Δ if let peripheral = peripherals?.first { bleConnect(peripheral) } } -
AccessorySetupKit ΛͬͨϖΞϦϯάखॱ 1. Info.plist ͷઃఆ 2. ASAccessorySession ͷ activate ϝιουͰΠϕϯτͷ
ϋϯυϦϯάΛ࣮ 3. ଓ͢ΔσόΠεใΛ ASDiscoveryDescriptor ʹࢦఆ 4. showPicker ϝιουΛݺͼग़͢ -
let descriptor = ASDiscoveryDescriptor() // Company IdentifierΛࢦఆ descriptor.bluetoothCompanyIdentifier = .init(0xFC94)
// Advertising Service UUID Λࢦఆ descriptor.bluetoothServiceUUID = .init(string: "181C") // Local Name Λࢦఆ descriptor.bluetoothNameSubstring = "BLE" // ରԠ͢ΔΦϓγϣϯΛࢦఆ descriptor.supportedOptions = [.bluetoothPairingLE, .bluetoothHID] -
let descriptor = ASDiscoveryDescriptor() // Company IdentifierΛࢦఆ descriptor.bluetoothCompanyIdentifier = .init(0xFC94)
// Advertising Service UUID Λࢦఆ descriptor.bluetoothServiceUUID = .init(string: "181C") // Local Name Λࢦఆ descriptor.bluetoothNameSubstring = "BLE" // ରԠ͢ΔΦϓγϣϯΛࢦఆ descriptor.supportedOptions = [.bluetoothPairingLE, .bluetoothHID] bluetoothCompanyIdenti f ier or bluetoothServiceUUID ͲͪΒ͔ࢦఆ͕ඞਢ(ࢦఆ͠ͳ͍ͱΫϥογϡ͢Δ) -
let descriptor = ASDiscoveryDescriptor() // Company IdentifierΛࢦఆ descriptor.bluetoothCompanyIdentifier = .init(0xFC94)
// Advertising Service UUID Λࢦఆ descriptor.bluetoothServiceUUID = .init(string: "1812") // Local Name Λࢦఆ descriptor.bluetoothNameSubstring = "M5" // ରԠ͢ΔΦϓγϣϯΛࢦఆ descriptor.supportedOptions = [.bluetoothPairingLE, .bluetoothHID] ϖΞϦϯά͕ඞཁͳσόΠεͰ͋ΕɺbluetoothPairingLEΛࢦఆ -
let descriptor = ASDiscoveryDescriptor() // Company IdentifierΛࢦఆ descriptor.bluetoothCompanyIdentifier = .init(0xFC94)
// Advertising Service UUID Λࢦఆ descriptor.bluetoothServiceUUID = .init(string: "1812") // Local Name Λࢦఆ descriptor.bluetoothNameSubstring = "M5" // ରԠ͢ΔΦϓγϣϯΛࢦఆ descriptor.supportedOptions = [.bluetoothPairingLE, .bluetoothHID] σόΠε͕Bluetooth LE HID(ΩʔϘʔυϚεೖྗ)ʹ ରԠ͍ͯ͠Ε bluetoothHID ඞཁ -
let displayName = “BLE-Demo" let productImage = UIImage(named: “ble-device-image")! let
displayItem = ASPickerDisplayItem( name: displayName, productImage: productImage, descriptor: descriptor ) try await session.showPicker(for: [displayItem]) -
let displayName = “BLE-Demo" let productImage = UIImage(named: “ble-device-image")! let
displayItem = ASPickerDisplayItem( name: displayName, productImage: productImage, descriptor: descriptor ) try await session.showPicker(for: [displayItem]) ϐοΧʔʹදࣔ͢Δ໊ͱͷΠϝʔδը૾Λࢦఆ લ߲Ͱઃఆͨ͠ASDiscoveryDescriptor͢ -
let displayName = “BLE-Demo” let productImage = UIImage(named: “ble-device-image")! let
displayItem = ASPickerDisplayItem( name: displayName, productImage: productImage, descriptor: descriptor ) try await session.showPicker(for: [displayItem]) ASAccessorySession ͷ showPicker ϝιουΛݺͼग़͢ -
extension BluetoothManager: CBCentralManagerDelegate { func centralManagerDidUpdateState(_ central: CBCentralManager) { switch
central.state { case .poweredOn: // Bluetooth ͕Φϯɺ͔ͭ༻ڐՄ͞Ε͍ͯΔ߹ case .poweredOff: // Bluetooth ͕Φϑɺ͘͠ݖݶະ֬ೝͷ߹ case .unauthorized: // Bluetooth ͷ༻ڐՄΛڋ൱ͨ͠߹ … } } } -
extension BluetoothManager: CBCentralManagerDelegate { func centralManagerDidUpdateState(_ central: CBCentralManager) { switch
central.state { case .poweredOn: // Bluetooth ͕Φϯɺ͔ͭ༻ڐՄ͞Ε͍ͯΔ߹ case .poweredOff: // Bluetooth ͕Φϑɺ͘͠ݖݶະ֬ೝͷ߹ case .unauthorized: // Bluetooth ͷ༻ڐՄΛڋ൱ͨ͠߹ … } } } AccessorySetupKit ͰηοτΞοϓࡁΈͷσόΠε͕͋Ε poweredOn ͕ฦΔ -
extension BluetoothManager: CBCentralManagerDelegate { func centralManagerDidUpdateState(_ central: CBCentralManager) { switch
central.state { case .poweredOn: // Bluetooth ͕Φϯɺ͔ͭ༻ڐՄ͞Ε͍ͯΔ߹ case .poweredOff: // Bluetooth ͕Φϑɺ͘͠ݖݶະ֬ೝͷ߹ case .unauthorized: // Bluetooth ͷ༻ڐՄΛڋ൱ͨ͠߹ … } } } ηοτΞοϓࡁΈͷσόΠε͕আ͞ΕΔͱ poweredO ff ͕ฦΔ -
func migratePairedDevice() async throws { let descriptor = ASDiscoveryDescriptor() descriptor.supportedOptions
= [.bluetoothPairingLE, .bluetoothHID] let displayName = “BLE-Demo" let productImage = UIImage(named: "ble-device-image")! let displayItem = ASMigrationDisplayItem( name: displayName, productImage: productImage, descriptor: descriptor ) // AccessorySetupKit ʹҠߦ͍ͨ͠ Peripheral Bluetooth Identifier Λࢦఆ͢Δ let bluetoothIdentifier = UUID(uuidString: "XXXXXXX-5CBD-9BFC-BC4C-4BBDE6436185") displayItem.peripheralIdentifier = bluetoothIdentifier try await session.showPicker(for: [displayItem]) } -
func migratePairedDevice() async throws { let descriptor = ASDiscoveryDescriptor() descriptor.supportedOptions
= [.bluetoothPairingLE, .bluetoothHID] let displayName = “BLE-Demo" let productImage = UIImage(named: "ble-device-image")! let displayItem = ASMigrationDisplayItem( name: displayName, productImage: productImage, descriptor: descriptor ) // AccessorySetupKit ʹҠߦ͍ͨ͠ Peripheral Bluetooth Identifier Λࢦఆ͢Δ let bluetoothIdentifier = UUID(uuidString: "XXXXXXX-5CBD-9BFC-BC4C-4BBDE6436185") displayItem.peripheralIdentifier = bluetoothIdentifier try await session.showPicker(for: [displayItem]) } peripheralIdenti f ier ʹ ϖΞϦϯάࡁΈBluetoothσόΠεͷUUIDΛ͓ͯ͘͠ -
·ͱΊ • AccessorySetupKit Λར༻͢Δ͜ͱͰɺBluetooth LE σόΠεͱͷϖΞϦϯ άηοτΞοϓϑϩʔΛҰମԽ͞ΕͨϢʔβʔମݧͰఏڙͰ͖Δ • ηοτΞοϓ͞Εͨ Bluetooth
LE σόΠεΛʮΞΫηαϦʯͱͯ͠ iOS ্Ͱ ཧͰ͖ΔΑ͏ʹͳΔ • ϖΞϦϯάࡁΈͷσόΠεΛҠߦ͢ΔAPI͕͋ΓɺطଘΞϓϦʹద༻Մೳ -
YODAN • 20259݄ݱࡏ App Store ʹެ։͞Ε͍ͯΔΞϓϦͰɺAccessorySetupKit ͕ΘΕ͍ͯΔέʔε͕͋·Γଘࡏ͍ͯ͠ͳ͍ • API ͕
iOS18 Ҏ߱ͱ͍͏ͷ͕ωοΫ͔͠Εͳ͍ • ৽نΞϓϦΛ࡞Δࡍͥͻʂ -
ࢀߟ • WWDC24: Meet AccessorySetupKit • https://developer.apple.com/videos/play/wwdc2024/10203/ • AccessorySetupKit |
Apple Developer Documentation • https://developer.apple.com/documentation/AccessorySetupKit • iOS 18 AccessorySetupKit: Everything BLE Developers Need To Know • https://punchthrough.com/ios18-accessorysetupkit-everything-ble- developers-need-to-know/