// Code inside modules can be shared between pages and other source files.
import UIKit//AppKit
import CoreBluetooth
import PlaygroundSupport
import PlaygroundBluetooth
struct BLEDevInfo {
var id:UUID
var name:String
var peripheral: CBPeripheral
}
extension BLEDevInfo: Hashable {
static func == (lhs: BLEDevInfo, rhs: BLEDevInfo) -> Bool {
return lhs.id == rhs.id
}
func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
}
class PageViewDelegate:UITableViewController,PlaygroundLiveViewSafeAreaContainer {
var dict: Set<BLEDevInfo> = []
let manager = PlaygroundBluetoothCentralManager(services: nil)
lazy var connectionView:PlaygroundBluetoothConnectionView = {
let viewDelegate: PlaygroundBluetoothConnectionViewDelegate & PlaygroundBluetoothConnectionViewDataSource = self
let connectionView = PlaygroundBluetoothConnectionView(centralManager: manager, delegate: viewDelegate)
connectionView.dataSource = viewDelegate
return connectionView
}()
override func viewDidLoad() {
super.viewDidLoad()
// Place the connection view within the rest of your page's content.
let page: UIViewController & PlaygroundLiveViewSafeAreaContainer = self
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
}
}
extension PageViewDelegate: PlaygroundBluetoothConnectionViewDataSource {
func
Swift Playground 中使用蓝牙
于 2020-05-27 12:34:45 首次发布
本文介绍了如何在Swift Playground环境中利用蓝牙功能,展示通过代码添加的tableview组件来显示连接的蓝牙设备名称。
摘要由CSDN通过智能技术生成