Skip to content

Commit

Permalink
WIP: Bluetoothが有効か確認する
Browse files Browse the repository at this point in the history
  • Loading branch information
Gurrium committed Apr 14, 2022
1 parent b2154c4 commit 993ce86
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
3 changes: 0 additions & 3 deletions Komusou/KomusouApp.swift
Expand Up @@ -9,10 +9,7 @@ import Combine
import SwiftUI

// TODO:
// - Reconnecting to Peripherals https://developer.apple.com/library/archive/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/BestPracticesForInteractingWithARemotePeripheralDevice/BestPracticesForInteractingWithARemotePeripheralDevice.html#//apple_ref/doc/uid/TP40013257-CH6-SW6
// - ユーザがセンサーを選ぶ画面を作る → ユーザが選んだセンサーがあればそれに接続する ということをすればそれぞれのセンサーを扱うクラスを安全に分離できそう
// - Mac対応
// - Bluetoothが有効にされていないときの対応
// - i18n

@main
Expand Down
6 changes: 6 additions & 0 deletions Komusou/PlayView.swift
Expand Up @@ -27,6 +27,12 @@ struct PlayView: View {
.sheet(isPresented: $isSettingsPresented) {
SettingsView()
}
// .alert("Bluetoothを有効にしてください", isPresented: .constant(BluetoothManager.shared.isBluetoothEnabled)) {
// // TODO: 設定画面に飛ばす
// Button("OK") {
// print("TODO: 設定画面に飛ばす")
// }
// } message: {}
}
}

Expand Down
9 changes: 4 additions & 5 deletions Komusou/Settings/SensorSettingView.swift
Expand Up @@ -168,6 +168,9 @@ final class BluetoothManager: NSObject {
static let shared = BluetoothManager()
private static let kSavedSpeedSensorUUIDKey = "speed_sensor_uuid_key"

var isBluetoothEnabled: Bool {
centralManager.state == .poweredOn
}
@Published
private(set) var discoveredPeripherals = [UUID: CBPeripheral]()

Expand All @@ -194,16 +197,12 @@ final class BluetoothManager: NSObject {
private var speedSensorPromise: ConnectingWithPeripheralFuture.Promise?

private let centralManager = CBCentralManager()
private var isBluetoothEnabled: Bool {
centralManager.state == .poweredOn
}
private var cancellables = Set<AnyCancellable>()

override init() {
super.init()

// TODO: 起動時の処理
// Bluetoothの許可の確認
// TODO: Bluetoothが有効にされているか確認する/ダイアログを出す

centralManager.delegate = self

Expand Down

0 comments on commit 993ce86

Please sign in to comment.