2017-07-17 29 views
0

我在iOS CoreBluetooth的 [CBPeripheralManager AddService:]上遇到了崩潰問題。iOS崩潰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]; 
} 

在此先感謝。

+0

共享一些代碼,您嘗試 –

+0

請分享您的代碼 – Dhiru

+0

代碼片段被添加,請你分享這種斷言失敗背後的原因。 –

回答

1

您還沒有實現你的BluetoothManager

看到this answer

This answer

回調更新我希望這將有助於你

+0

我已經實現了CBPeripheralManager的所有代表,包括CBCentral代表。一般來說,它工作正常。通常我無法用意圖重現這個問題。但它突然發生。 –