【问题标题】:iOS crash Assertion Failure on CBPeripheralManager AddService:CBPeripheralManager AddService 上的 iOS 崩溃断言失败:
【发布时间】:2017-07-17 04:37:38
【问题描述】:

我在 iOS CoreBluetooth 上遇到崩溃问题 [CBPeripheralManager AddService:]

似乎是由于addService 方法中的断言失败而发生的。尝试了很多方法,仍然无法解决问题。

据我了解,这不是空指针异常,因为我已经测试过将 nil 值作为 AddService 参数传递,这会产生不同的问题。

我已经实现了 CBPeripheralManager 的所有代表,包括 CBCentral 代表。

一般来说它工作正常。通常我不能故意重现这个问题。但它突然发生。

请帮忙 . 崩溃日志:

0   CoreFoundation                 0x18b3cafe0 __exceptionPreprocess + 124
1   libobjc.A.dylib                0x189e2c538 objc_exception_throw + 56
2   CoreFoundation                 0x18b3caeb4 +[NSException raise:format:arguments:] + 104
3   Foundation                     0x18be62720 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 112
4   CoreBluetooth                  0x1922ab420 -[CBPeripheralManager addService:] + 820
5   MyApp                        0x10110e1f4 -[MyPeripheralManager addServiceIntoPeripheralManager] (MyPeripheralManager.m:202)

代码片段:

-(void)addService{
if (!isServiceAdded) {
    CLLog("Add Service timer started");
    [backgroundTaskManager manageBackgroundRunningTask];
    /*
     AddService will be called after 5 seconds
     when application launching finished or iOS BT on
     */
    [self performSelector:@selector(addServiceIntoPeripheralManager) withObject:self afterDelay:SERVICE_ADDING_DELAY]; // 5 secs

} else {
    CLDbg("Service already added");
}
}
- (void)addServiceIntoPeripheralManager{
CLLog("Add Service timer expired");
CLDbg("Service Adding: %@", [UUIDString]);
[cbPeripheralManager addService:Service];
}

提前致谢。

【问题讨论】:

  • 分享一些你尝试过的代码
  • 请分享您的代码
  • 添加了sn-p代码,请分享一下这种断言失败的原因。
  • 断言失败的文本是什么?这将描述出了什么问题。使用计时器来延迟操作是一种代码味道。你为什么这样做?
  • 会有一个文本描述被传递给断言失败;您需要在控制台日志中找到它,或者您只是在猜测。您应该只添加服务以响应开机状态(或开机状态加上后续用户操作)。您的应用不能多次尝试添加服务

标签: ios crash bluetooth-lowenergy


【解决方案1】:

您没有实现 BluetoothManager 的回调更新

this answer

This answer

希望对你有帮助

【讨论】:

  • 我已经实现了 CBPeripheralManager 的所有代表,包括 CBCentral 代表。一般来说,它工作正常。通常我不能故意重现这个问题。但它突然发生。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-01
  • 1970-01-01
  • 2014-10-03
相关资源
最近更新 更多