CoreBluetooth XPC Connection Invalid on dismiss viewcontroller

xpc error connection invalid -corebluetooth
shortcuts xpc connection interrupted
an error occurred on the xpc connection to setup the background session
api misuse: discovering services for peripheral
ios bluetooth pairing programmatically swift
cbcentralmanager
ios swift bluetooth example
swiftui bluetooth

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?

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

(CBCentralManager will not be deallocated)

[CoreBluetooth] XPC connection invalid · Issue #156 , Getting an : [CoreBluetooth] XPC connection invalid, if removed is not held by a view controller, or that view controller is being released. I wrote some code and tried to do app but i have a problem: [CoreBluetooth] XPC connection invalid. I think that my view are properly relative with code. I don't know where is the problem. Build succed so it shouldn't be a problem with code. It's my first time with Xcode, Swift, and MacBook, so I really don't get on with it.

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

How to solve 'XPC connection invalid' on iOS 10, I think the problem might be that the instance of your Bluetooth() class created in ViewController.viewDidLoad() is going out of scope just as CoreBluetooth is  I think the problem might be that the instance of your Bluetooth() class created in ViewController.viewDidLoad() is going out of scope just as CoreBluetooth is initializing in the background (asynchronously).

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

XPC Error CoreBluetooth |Apple Developer Forums, I'm currently looking into CoreBluetooth, but I'm already struggeling with the simple setup. On starting the test [CoreBluetooth] XPC connection invalid class ViewController: NSViewController, CBCentralManagerDelegate,  XPC Connection Interrupted. Terminating since there is no system app. I have Flurry analytics integrated in my app by the way, not sure if thats an issue. How can I fix this issue? My searches for XPC connections do not seem to return problems similar to mine.

try this:

CBPeripheral *mConnectedPeripheral;

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

User oOEric, "[CoreBlueooth] XPC Connection Invalid" Is there something in specific that has to be cleaned up with Bluetooth before the viewcontroller is dismissed? The problem lied in the storyboard for me as well. I created a new project and laid out the views and everything seemed to be working fine. I found these couple lines in the storyboard source (right click on storyboard and select view as -> source code) which weren't common between the working version and the broken version:

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.

[Xcode 8][Swift 3] Why does scanForPeripherals stop when I segue , Top network posts. 8 CoreBluetooth XPC Connection Invalid on dismiss viewcontroller · 6 React Native - Why we use the tintColor property for Image component  r/iOSProgramming: A subreddit to share articles, code samples, open source projects and anything else related to iOS, macOS, watchOS, or tvOS …

It also says "[CoreBluetooth] XPC Connection Invalid". Has anyone If you press back and go back to the main ViewController the error appears. Weirdly, this  Get List Of BLE Devices Using CoreBluetooth On iOS – Swift January 21, 2016 February 8, 2017 / wingoodharry This post will show you just the minimum effort needed to get a list of BLE (Bluetooth 4.0) devices that are advertising on your iOS device.

Comments
  • This doesn't seem to be related to the view controller. I get this message every time CBCentralManager gets deallocated. Simply test with a local variable, e.g. CBCentralManager(delegate: nil, queue: nil). As soon as the scope ends, that error message pops up.
  • I had the same error ( "[CoreBlueooth] XPC Connection Invalid")... in my case I was instantiating CBCentralManager outside of a view controller. Instantiating it in a view controller solved the issue for me.
  • Thank you. This helped me to solve my issue. You can make the CBCentralManager as a class variable (declare it outside the function) instead of local variable.
  • I had a similar problem, in my app I have a first screen where BLE devices are listed and when you click on one device, you are bring to another screen and I had this descriptiveness error message. The CBCentralManager is a singleton you have to pass from view to view...
  • When things like that happens, try to isolate your problem so you can identify what makes it fail. You may also comment here with more details. There are plenty of open source projects out there that scans for devices and even lets you write to characteristics, etc. chenee/DarkBlue was helpful to me. For swift projects: Pluto-Y/Swift-LightBlue. In my case, I started a blank project and did the minimal code to communicate with my device, had to add NSBluetoothPeripheralUsageDescription and it worked 👍
  • @VineeshTP Can you elaborate? As I commented above, isolate your problem and find what's causing this.
  • @PravinS. try isolating your problem in a separate project, refer to this comment: stackoverflow.com/questions/43880346/… feel free to add details or error message you may be getting here. This solution worked for me and still works on an application in production right now ;)
  • @Oscar: Actually I don't remember, it is 2 years back. Could you please elaborate your problem?
  • I'm getting "[CoreBlueooth] XPC Connection Invalid", which was the original topic here. I've tried another project, a demo project by someone else, and it produces the same message in the console.