I was followed the code of How to get the status of bluetooth (ON/OFF) in iphone programatically to get the status of bluetooth.
But when I pop the viewController by back navigation button, the app crashed with following error.
[CoreBluetooth] XPC connection invalid
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x170261c80 of class CBCentralManager was deallocated while key value observers were still registered with it. Current observation info: ( Context: 0x1aa9c3710, Property: 0x170056b90> Context: 0x1aa9c3710, Property: 0x170056b00> Context: 0x1aa9c3710, Property: 0x170056b90> Context: 0x1aa9c3710, Property: 0x170056b00> )'
I was tried to remove the observers stated above when calling viewWillDisappear, but error still comes.
[self.bluetoothManager removeObserver:self forKeyPath:@"state"];
[self.bluetoothManager removeObserver:self forKeyPath:@"delegate"];
And I tried
self.bluetoothManager.delegate = nil;
And
self.bluetoothManager = nil;
Sadly all of them no works.
Please give helps.
Update:
I want to show the system pop alert while bluetooth is not turned ON when calling - (void)detectBluetooth. So I add
[self.bluetoothManager init];
in - (void)detectBluetooth.
I found that make the error.
But I can't figure out another method to show the default popup(which with SETTING button).