IOS vs OSX BLE:实例化 CBCentralManager - iOS 的编码
IOS vs OSX BLE: Instantiating CBCentralManager - coding for iOS
我正在学习 iOS 与 OSX BLE。
我注意到我无法在 iOS 中实例化 CBCentralManager,因为:
[CoreBluetooth] XPC connection invalid
Unsupported
与 OSX 相比,因为 iOS 平台没有 'App Sandbox' 特性,我可以在其中设置 BLE 使用。
这是我的 iOS 代码:
import SwiftUI
struct ContentView: View {
@ObservedObject var bleManager = BLEManager()
var body: some View {
ZStack {
Color("Background")
Text("Hello")
}
}
}
class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate {
var centralManager: CBCentralManager!
override init() {
super.init()
centralManager = CBCentralManager(delegate: self, queue: nil)
}
public func centralManagerDidUpdateState(_ central: CBCentralManager) {
switch central.state {
case .poweredOn:
print("power is on")
case .resetting:
print("Resetting")
case .unsupported:
print("Unsupported")
case .unauthorized:
print("UnAuthorized")
case .unknown:
print("UnKnown")
case .poweredOff:
print("Powered OFF")
@unknown default:
print("**** Default ****")
}
}
}
这是必需的 .plist 条目:
我知道 iPhone 既可以是 BLE 中心也可以是外围设备。
简单问题:如何为 iOS 编写真正的 CBCentralMaster?
我只是在这里采取一些小步骤:外围检测编码。
...然后从那里继续。
查看主要 Core Bluetooth 文档:
Your app will crash if its Info.plist doesn’t include usage description keys for the types of data it needs to access. To access Core Bluetooth APIs on apps linked on or after iOS 13, include the NSBluetoothAlwaysUsageDescription key. In iOS 12 and earlier, include NSBluetoothPeripheralUsageDescription to access Bluetooth peripheral data.
您 运行 是在模拟器上(不受支持的地方)而不是在设备上吗?
我正在学习 iOS 与 OSX BLE。
我注意到我无法在 iOS 中实例化 CBCentralManager,因为:
[CoreBluetooth] XPC connection invalid
Unsupported
与 OSX 相比,因为 iOS 平台没有 'App Sandbox' 特性,我可以在其中设置 BLE 使用。
这是我的 iOS 代码:
import SwiftUI
struct ContentView: View {
@ObservedObject var bleManager = BLEManager()
var body: some View {
ZStack {
Color("Background")
Text("Hello")
}
}
}
class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate {
var centralManager: CBCentralManager!
override init() {
super.init()
centralManager = CBCentralManager(delegate: self, queue: nil)
}
public func centralManagerDidUpdateState(_ central: CBCentralManager) {
switch central.state {
case .poweredOn:
print("power is on")
case .resetting:
print("Resetting")
case .unsupported:
print("Unsupported")
case .unauthorized:
print("UnAuthorized")
case .unknown:
print("UnKnown")
case .poweredOff:
print("Powered OFF")
@unknown default:
print("**** Default ****")
}
}
}
这是必需的 .plist 条目:
我知道 iPhone 既可以是 BLE 中心也可以是外围设备。
简单问题:如何为 iOS 编写真正的 CBCentralMaster?
我只是在这里采取一些小步骤:外围检测编码。
...然后从那里继续。
查看主要 Core Bluetooth 文档:
Your app will crash if its Info.plist doesn’t include usage description keys for the types of data it needs to access. To access Core Bluetooth APIs on apps linked on or after iOS 13, include the NSBluetoothAlwaysUsageDescription key. In iOS 12 and earlier, include NSBluetoothPeripheralUsageDescription to access Bluetooth peripheral data.
您 运行 是在模拟器上(不受支持的地方)而不是在设备上吗?