我在didConnect函数中设置了一个断点以打印出委托的值,并且它以nil
的形式返回,我不知道为什么
@objc protocol KestrelDeviceConnectDelegate {
func didConnect()
func didDisconnect()
}
@objcMembers
class KestrelDeviceConnect: NSObject{
static let singleton = KestrelDeviceConnect()
public weak var delegate: KestrelDeviceConnectDelegate?
func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
self.isInitialReading = false
self.kestrelIsConnected = true
kestrelPeripheral.discoverServices(nil)
delegate?.didConnect()
}
}
在我的目标VC的viewDidLoad
中
_kestrelVC = [[KestrelDeviceConnect alloc]init];
[_kestrelVC setDelegate:self];
答案 0 :(得分:0)
问题是初始化一个新的KestrelDeviceConnect
实例,所以没有_kestrelVC = [[KestrelDeviceConnect alloc]init];
有效的是_kestrelVC = [KestrelDeviceConnect singleton]