CoreBluetooth XPC Connection Invalid on dismiss viewcontroller

一笑奈何 提交于 2019-12-12 09:30:58

问题


After I have finished disconnecting from my bluetooth devices, seeing that they have disconnected in the didDisconnectPeripheral delegate, I attempt to dismiss my viewcontroller.

When this happens I see the message: "[CoreBlueooth] XPC Connection Invalid"

Is there something in specific that has to be cleaned up with Bluetooth before the viewcontroller is dismissed?


回答1:


I placed CBCentralManager to a singleton and the error message is solved.

(CBCentralManager will not be deallocated)




回答2:


I was getting the following message:

[CoreBlueooth] XPC Connection Invalid

And I wasn't able to scan BLE devices using a quite simple implementation of the following:

NSObject<CBCentralManagerDelegate, CBPeripheralDelegate>

The solution for me was to add a value in my Info.plist for Privacy - Bluetooth Peripheral Usage Description NSBluetoothPeripheralUsageDescription describing what I do with Bluetooth Peripheral.

Looks like this in info.plist:

<key>NSBluetoothPeripheralUsageDescription</key>
<string>Play with BLE Compatible devices<string>

Write something more accurate in here ;)




回答3:


CBCentralManager reference should be a strong reference to the class as a member variable. It cannot work as a local reference.




回答4:


try this:

CBPeripheral *mConnectedPeripheral;

-(void)viewDidDisappear:(BOOL)animated{
    [_centralManager cancelPeripheralConnection:mConnectedPeripheral];
}



回答5:


Same issue happened when I moved all my BLE methods to dedicated class (BLEController) and keep ViewController clean. First I tried to initialize it inside ViewController class like this:

let _ = BLEController()

This leads to "XPC Connection invalid" issue. What really helped is to move the object to AppDelegate class. To be honest I have no idea why it helped and what is the difference.




回答6:


Ok, I ran into that problem and after trying to add the necessary key to the Info.plist it still did worked and I had no view to use at this point (it was in the AppDelegate). So if it still don't work for you try the following.

I used to use: (in Swift)

_ = BluetoothMngr.init(config: bleConfig)

The problem here was that the variable managing the Bluetooth was not retained so when we add BLE callback these one ended up in an empty class, so simply create a global variable where it's gonna be retained (this is why it works with singleton and view these are retained) like this.

self.bleMngr = BluetoothMngr.init(config: bleConfig)

Worked for me, hope it will help.




回答7:


In my case, I turned off app sandbox from capabilities, and it worked



来源:https://stackoverflow.com/questions/43880346/corebluetooth-xpc-connection-invalid-on-dismiss-viewcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!