[BLE]CBCentralManager(delegate:, queue:) throw exception:'String does not represent a valid UUID' only on IOS 16

174 Views Asked by At

I try to develop an IOS app using Bluetooth Low Energy to Scan and Advertise data with CoreBluetooth. With IOS version < 16, My App was work normally

But with IOS 16 The Advertising data work well but when calling Scan:

import UIKit
import CoreBluetooth

class ViewController: UIViewController, CBCentralManagerDelegate{
    var centralManager : CBCentralManager!
    func centralManagerDidUpdateState(_ central: CBCentralManager) {
        switch central.state{
            
        case .unknown:
            print("Error!")
        case .resetting:
            print("Error!")
        case .unsupported:
            print("Error!")
        case .unauthorized:
            print("Error!")
        case .poweredOff:
            print("Error!")
        case .poweredOn:
            central.scanForPeripherals(withServices: nil)
        @unknown default:
            print("Error!")
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        centralManager = CBCentralManager(delegate: self, queue: nil)
    }
    
    
}

My app crashed with the exception:

libc++abi: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'String  does not represent a valid UUID'
terminating with uncaught exception of type NSException
CoreSimulator 857.13 - Device: iPhone 14 (EF5FBAFD-8E40-4A10-802E-B04B8EC0F1DF) - Runtime: iOS 16.1 (20B72) - DeviceType: iPhone 14

Does Anyone get the same issue with me and How did you solve it?

0

There are 0 best solutions below