Lou_257
Lou_257

Reputation: 331

CoreBluetooth XPC Connection Invalid on dismiss viewcontroller

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?

Upvotes: 19

Views: 17607

Answers (7)

Dmitry Borodaenko
Dmitry Borodaenko

Reputation: 11

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.

Upvotes: 1

Chulseung
Chulseung

Reputation: 1

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

Upvotes: 0

Debasish Chowdhury
Debasish Chowdhury

Reputation: 131

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

Upvotes: 4

Rémy Blanc
Rémy Blanc

Reputation: 313

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.

Upvotes: 0

GabLeRoux
GabLeRoux

Reputation: 17953

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 ;)

Upvotes: 6

Garima Paliwal
Garima Paliwal

Reputation: 21

try this:

CBPeripheral *mConnectedPeripheral;

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

Upvotes: 1

oOEric
oOEric

Reputation: 1079

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

(CBCentralManager will not be deallocated)

Upvotes: 11

Related Questions