Slide 1

Slide 1 text

STORES 株式会社 @nekowen 2024年 7月 5日(金) potatotips #88 5分で理解するAccessorySetupKit

Slide 2

Slide 2 text

自己紹介

Slide 3

Slide 3 text

自己紹介 @nekowen (Ryoya Kobitsu) STORES 株式会社所属 ・WWDC24 に現地参加します ・iOSDC Japan 2024 で登壇します 3

Slide 4

Slide 4 text

最初に 本LTは WWDC24 の公開情報(セッション動画、ドキュメント)を元に お話しします 4

Slide 5

Slide 5 text

AccessorySetupKit で実現できること

Slide 6

Slide 6 text

今までのアクセサリ機器とのペアリング体験 6 https://developer.apple.com/videos/play/wwdc2024/10203

Slide 7

Slide 7 text

これからのアクセサリ機器とのペアリング体験 ・Bluetoothアクセサリ機器とのペアリング や接続をシームレスに行える ・アクセサリの接続は「プライバシーとセ キュリティ」で管理される ・iOS / iPadOS で利用可能 7 https://developer.apple.com/videos/play/wwdc2024/10203

Slide 8

Slide 8 text

接続したい BLE アクセサリのアドバタイズパケットを知る 8 ・Local Name(デバイス名) ・Service UUID ・Service Data ・Manufacturer Specific Data / Company ID(ベンダー識別子)

Slide 9

Slide 9 text

Info.plist に 利用情報を宣言する 9 (Required) NSAccessorySetupKitSupports NSAccessorySetupBluetoothCompanyIdentifiers NSAccessorySetupBluetoothNames NSAccessorySetupBluetoothServices

Slide 10

Slide 10 text

ASAccessorySession のアクティベート 10 let session = ASAccessorySession() override func viewDidLoad() { super.viewDidLoad() session.activate(on: DispatchQueue.main) { [weak self] event in // アクセサリが追加・削除されたり、   // シートの表示・非表示のタイミングなどで呼ばれる } }

Slide 11

Slide 11 text

ASDiscoveryDescriptor に検出するアドバタイズデータを指定 11 let descriptor = ASDiscoveryDescriptor() // 「どちらか」一つ指定が必要 descriptor.bluetoothCompanyIdentifier = ... descriptor.bluetoothNameSubstring = ... // 「どれか」一つ指定が必要 descriptor.bluetoothServiceUUID = .init(string: "...") descriptor.bluetoothManufacturerDataBlob = ... descriptor.bluetoothServiceDataBlob = ...

Slide 12

Slide 12 text

ASPickerDisplayItem を生成して showPicker を呼び出す 12 let displayItem = ASPickerDisplayItem( name: "デバイス名", productImage: UIImage(named: ...), descriptor: descriptor ) // セットアップシートを表示 session.showPicker(for: [displayItem]) { … } https://developer.apple.com/videos/play/wwdc2024/10203

Slide 13

Slide 13 text

Core Bluetooth にペアリングした機器の情報を引き継ぐ 13 self.session.activate(on: DispatchQueue.main) { [weak self] event in switch event.eventType { case .accessoryAdded: pickedAccessory = event.accessory case .pickerDidDismiss: // ペアリングした機器の識別子をCore Bluetooth に引き継ぐ let bluetoothIdentifier = pickedAccessory.bluetoothIdentifier ... } }

Slide 14

Slide 14 text

Core Bluetooth にペアリングした機器の情報を引き継ぐ 14 self.session.activate(on: DispatchQueue.main) { [weak self] event in switch event.eventType { case .accessoryAdded: pickedAccessory = event.accessory case .pickerDidDismiss: // ペアリングした機器の識別子をCore Bluetooth に引き継ぐ let bluetoothIdentifier = pickedAccessory.bluetoothIdentifier ... } }

Slide 15

Slide 15 text

まとめ 15 ・AccessorySetupKit は従来のペアリングの手間を省き、アクセサリとの接続 をスムーズにしてくれます ・ユーザーに接続するアクセサリを視覚的に分かりやすくできる ・Bluetooth利用権限が不要、セキュアにペアリングできる

Slide 16

Slide 16 text

参考 16 Meet AccessorySetupKit https://developer.apple.com/videos/play/wwdc2024/10203/ Discovering and configuring accessories https://developer.apple.com/documentation/accessorysetupkit/discovering-and-con figuring-accessories ASAccessorySession https://developer.apple.com/documentation/accessorysetupkit/asaccessorysession

Slide 17

Slide 17 text

17 ご清聴ありがとうございました