Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error nil in central.scanWithDuration #110

Open
ironrustem opened this issue Mar 26, 2021 · 2 comments
Open

Error nil in central.scanWithDuration #110

ironrustem opened this issue Mar 26, 2021 · 2 comments

Comments

@ironrustem
Copy link

I have problem. I scan with central.scanWithDuration, but I get nil error. Can you help me please? Why?

My code:`

private var discoveries = [BKDiscovery]()
let central = BKCentral()

func central(_ central: BKCentral, remotePeripheralDidDisconnect remotePeripheral: BKRemotePeripheral) {
    print("DidDisconnect")
}

func availabilityObserver(_ availabilityObservable: BKAvailabilityObservable, availabilityDidChange availability: BKAvailability) {
    if availability == .available {
        print("start scan")
        scan()
    } else {
        central.interruptScan()
    }
}

func availabilityObserver(_ availabilityObservable: BKAvailabilityObservable, unavailabilityCauseDidChange unavailabilityCause: BKUnavailabilityCause) {
    print("CauseDidChange")
}

override func viewDidLoad() {
    super.viewDidLoad()
    
    tableView.delegate = self
    tableView.dataSource = self

    startCentral()
}


private func startCentral() {
    do {
        central.delegate = self
        central.addAvailabilityObserver(self)
        let dataServiceUUID = UUID(uuidString: "6E6B5C64-FAF7-40AE-9C21-D4933AF45B23")!
        let dataServiceCharacteristicUUID = UUID(uuidString: "477A2967-1FAB-4DC5-920A-DEE5DE685A3D")!
        let configuration = BKConfiguration(dataServiceUUID: dataServiceUUID, dataServiceCharacteristicUUID: dataServiceCharacteristicUUID)
        try central.startWithConfiguration(configuration)
    } catch let error {
        print("Error while starting: \(error)")
    }
}


private func scan() {
    central.scanWithDuration(7, progressHandler: { newDiscoveries in
        print(newDiscoveries)
    }, completionHandler: { result, error in
       print("errorScan \(error)")
        print(result)
    })
}`
@rhummelmose
Copy link
Owner

Check the example please :)

@longlz19
Copy link

The example also returns an error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants