didConnect is not called on iPad Pro, but works on iPhone

57 Views Asked by At

I have been experiencing this strange error on my iPad Pro (iOS 11.2) where it discovers the peripheral, but couldn't connect. Been struggling with this for days now.

My iPhone on the other hand connects and collects data without any problem. Can some of you point me to what went wrong here? Any help greatly appreciated. Here is my code:

//Update: This happens on all new devices, ex. iPad Pro, Pixel XL, new macbook pros, iPhone 7, etc. Maybe it has something to do with new hardwares? Tested with LightBlue app.

func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {

    //Use this snippet if the device name is advertised. Optionals are handled well here.
    if let peripheralName = advertisementData[CBAdvertisementDataLocalNameKey] as? NSString {
        if peripheralName as String == deviceDetails.deviceName{
            print("Here I am \(peripheralName)")
            //bleManager.myCentralManager.stopScan()
            myPeripheral = peripheral
            centralManager.stopScan()
            centralManager.connect(myPeripheral, options: nil)
            myPeripheral.delegate = self

           // bleManager.myPeripheral = peripheral
            //bleManager.myPeripheral.delegate = self //Setting the delegate for the peripheral and now we can implement the methods from this view controller
           // bleManager.myCentralManager.connect(bleManager.myPeripheral!, options: nil) //Connecting to the peripheral
            print("Connected to \(myPeripheral)")

        } else {
            //Device name not found
        }
    }
}

//MARK: Step 3 - Connecting to peripheral
func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
    print("Connection success")
    peripheral.discoverServices([deviceDetails.service_UUID])           //Discovering specific service
    timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(updateTimer), userInfo: nil, repeats: true)
}

I am also pasting my log data when run on iPad:

powered ON
Here I am GBStrain
Connected to Optional(<CBPeripheral: 0x1c83, identifier = <identifier>, name = GBStrain, state = connecting>)

Thanks in advance!

0

There are 0 best solutions below