gpt4 book ai didi

ios - 返回查看 Controller 时,Core Bluetooth 不会恢复

转载 作者:行者123 更新时间:2023-11-29 00:41:30 25 4
gpt4 key购买 nike

我正在研究蓝牙心率监测器,我遵循了 https://www.raywenderlich.com/52080/introduction-core-bluetooth-building-heart-rate-monitor 中的代码

我现在的应用程序运行良好。在同一个应用程序中,我有几个其他的 View Controller ,它们可以做一些其他的事情,比如登录页面和简单的“关于我们”页面。我遇到的问题是,当返回包含实际心率监视器的 View Controller 时,监视器位于 0 并且不会更新值。

我有遗嘱恢复代码和委托(delegate):

-(void)centralManager:(CBCentralManager *)central willRestoreState:(NSDictionary *)state {

NSLog(@"willRestoreState called");
self.polarH7HRMPeripheral = [state[CBCentralManagerRestoredStatePeripheralsKey] firstItem];
self.polarH7HRMPeripheral.delegate = self;
}

中央经理是这样声明的:

 CBCentralManager *centralManager =[[CBCentralManager alloc] initWithDelegate:self queue:nil options:@{ CBCentralManagerOptionRestoreIdentifierKey:@"myCentralManagerIdentifier" }];

当回到 View Controller 时,我注意到 willRestoreState 没有被调用。

我不知道下一步要看哪里。任何人都可以帮忙吗?提前致谢。

最佳答案

如果 CBCentralManager 的对象被释放,那么这个方法将不起作用,因为这是 CBCentralManager 的委托(delegate)方法。

要使其正常工作,您必须重新初始化 CBCentralManager 的对象,这样您才能获得心率。

像这样

self.hrCBManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];

关于ios - 返回查看 Controller 时,Core Bluetooth 不会恢复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39370264/

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