gpt4 book ai didi

ios - 为什么不调用 CBPeripheralManagerDelegate 方法?

转载 作者:搜寻专家 更新时间:2023-11-01 06:08:52 25 4
gpt4 key购买 nike

尽管我已经将类初始化为 var bluetoothManager = CBPeripheralManager(delegate: self, queue: nil, options: nil)

并且已经在我的 Bundle 中添加了 BlueTooth Framework。

import UIKit
import CoreBluetooth

class AppSettingsViewController: UIViewController {



override func viewDidLoad() {
super.viewDidLoad()

var bluetoothManager = CBPeripheralManager(delegate: self, queue: nil, options: nil)


}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


}

extension AppSettingsViewController : CBPeripheralManagerDelegate{


func peripheralManagerDidUpdateState(peripheral: CBPeripheralManager!) {

if peripheral.state == CBPeripheralManagerState.PoweredOn{

println("broadcasting")



}else if peripheral.state == CBPeripheralManagerState.PoweredOff{

println("no bluetooth found")

}else if peripheral.state == CBPeripheralManagerState.Unauthorized {

println("This option is not allowed by your application")

}

}


}

最佳答案

使您的 bluetoothManager 成为一个实例变量。目前它在 viewDidLoad() 完成时被释放。

关于ios - 为什么不调用 CBPeripheralManagerDelegate 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29816942/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com