Ios 使用带有BLE和HM-10的Swift游乐场
我目前正在尝试建立一个可以与HM-18 BLE模块通信的swift操场 我是斯威夫特的新手。我只是不知道委托的事情以及我需要在那里分配什么对象(???) 让我分解一行,解释我认为我理解的部分:Ios 使用带有BLE和HM-10的Swift游乐场,ios,swift,bluetooth,bluetooth-lowenergy,ipad-playgrounds,Ios,Swift,Bluetooth,Bluetooth Lowenergy,Ipad Playgrounds,我目前正在尝试建立一个可以与HM-18 BLE模块通信的swift操场 我是斯威夫特的新手。我只是不知道委托的事情以及我需要在那里分配什么对象(???) 让我分解一行,解释我认为我理解的部分: 让managerDelegate:PlaygroundBluetoothCentralManagerDelegate=??? 让我们声明一个带有名称managerDelegate的常量,该常量必须为类型PlaygroundBluetoothCentralManagerDelegate 我只是不知道比赛之后
让managerDelegate:PlaygroundBluetoothCentralManagerDelegate=???
让我们声明一个带有名称managerDelegate的常量,该常量必须为类型PlaygroundBluetoothCentralManagerDelegate
我只是不知道比赛之后会发生什么=
这是我目前的代码:
import CoreBluetooth
import PlaygroundBluetooth
import PlaygroundSupport
// Create State enum (shape)
enum Shape: String, CaseIterable {
case on, off
}
struct ContentView: View {
// Get all cases
let LEDStates = Shape.allCases
// State Variable (state binding observables -> learn)
@State private var selectedStateIndex = 0
// I dont get this part from: https://developer.apple.com/documentation/playgroundbluetooth/connecting_to_bluetooth_peripherals_in_swift_playgrounds
let managerDelegate: PlaygroundBluetoothCentralManagerDelegate = ???
let manager = PlaygroundBluetoothCentralManager(services: nil)
manager.delegate = managerDelegate
let viewDelegate: PlaygroundBluetoothConnectionViewDelegate = ???
let connectionView = PlaygroundBluetoothConnectionView(centralManager: manager, delegate: viewDelegate)
connectionView.dataSource = viewDelegate
// Place the connection view within the rest of your page's content.
let page: UIViewController & PlaygroundLiveViewSafeAreaContainer = ???
page.view.addSubview(connectionView)
// Position the connection view in the top right corner.
connectionView.topAnchor.constraint(equalTo: page.liveViewSafeAreaGuide.topAnchor, constant: 20).isActive = true
connectionView.trailingAnchor.constraint(equalTo: page.liveViewSafeAreaGuide.trailingAnchor, constant: -20).isActive = true
// This I understand
PlaygroundPage.current.liveView = page
var body: some View {
ZStack(alignment: .bottomTrailing) {
Picker("LED State", selection: $selectedStateIndex) {
ForEach(0..<LEDStates.count) { index in
Text(self.LEDStates[index].rawValue).tag(index)
}
}.pickerStyle(SegmentedPickerStyle())
.padding(10)
.background(Color.black.opacity(0.5))
}
}
}
PlaygroundPage.current.setLiveView(ContentView())
导入核心蓝牙
导入PlaygroundBluetooth
导入PlaygroundSupport
//创建状态枚举(形状)
枚举形状:字符串,可大小写{
开,关
}
结构ContentView:View{
//拿到所有的箱子
设LEDStates=Shape.allCases
//状态变量(状态绑定观察值->学习)
@状态私有变量selectedStateIndex=0
//我不从以下方面获得此部分:https://developer.apple.com/documentation/playgroundbluetooth/connecting_to_bluetooth_peripherals_in_swift_playgrounds
让managerDelegate:PlaygroundBluetoothCentralManagerDelegate=???
let manager=PlaygroundBluetoothCentralManager(服务:无)
manager.delegate=managerDelegate
让viewDelegate:PlaygroundBluetoothConnectionViewDelegate=???
让connectionView=PlayGroundBluetooth连接视图(中央管理器:管理器,代理:视图代理)
connectionView.dataSource=viewDelegate
//将连接视图放在页面内容的其余部分中。
让页面:UIViewController&PlaygroundLiveViewSafeAreaContainer=???
page.view.addSubview(connectionView)
//将连接视图放置在右上角。
connectionView.topAnchor.constraint(等式:page.liveViewSafeAreaGuide.topAnchor,常量:20)。isActive=true
connectionView.trailingAnchor.constraint(等式:page.liveViewSafeAreaGuide.trailingAnchor,常数:-20)。isActive=true
//这我理解
PlaygroundPage.current.liveView=第页
var body:一些观点{
ZStack(对齐:.bottomTrailing){
选择器(“LED状态”,选择:$selectedStateIndex){
弗雷奇(0..您需要声明一个符合PlaygroundBluetoothCentralMananagerDelegate
的类,并分配该类的实例。我必须在哪里声明它?类中必须包含什么?在您的游乐场中创建类。协议已记录在案。您的类需要实现处理B类所需的函数luetooth事件。好的,我从GitHub获得了这个Bluetooth串行类,我想这就是你的意思,对吗?你可以从这个类开始工作;它是为CoreBluetooth构建的;你需要对它进行修改,以使用PlayPlayPlayBluetooth。你需要声明一个符合PlayGroundBluetoothCentralManagerDelegate
的类,并分配一个实例那类的。我必须在哪里声明它?在类内部必须做什么?在你的操场上创建类。协议被记录。你的类需要实现处理蓝牙事件所需的函数。好的,我从GitHub得到了这个BluetoothSerial类,我想这就是你的意思,对吗?你可以从t、 它是为CoreBluetooth而构建的;您需要对其进行修改以使用游乐场蓝牙