osx - Why won't my mac discover devices in this Core Bluetooth App? -




i've been working on core bluetooth mac app , i've run issues discovery part on mac. code has failed to discovery devices despite fact same devices appear in bluetooth setting of mac. it's code issue can't seem figure out. code:

import cocoa import corebluetooth  class viewcontroller: nsviewcontroller, cbcentralmanagerdelegate { var centralmanager: cbcentralmanager! override func viewdidload() {     super.viewdidload()     centralmanager = cbcentralmanager(delegate: self, queue: dispatchqueue.main)      // additional setup after loading view. }  override var representedobject: any? {     didset {     // update view, if loaded.     } }  func setupbt() {  }  func centralmanagerdidupdatestate(_ central: cbcentralmanager) {     var statusmessage = ""     switch central.state {     case .poweredon:         statusmessage = "bluetooth status: turned on"      case .poweredoff:         statusmessage = "bluetooth status: turned off"      case .resetting:         statusmessage = "bluetooth status: resetting"      case .unauthorized:         statusmessage = "bluetooth status: not authorized"      case .unsupported:         statusmessage = "bluetooth status: not supported"      default:         statusmessage = "bluetooth status: unknown"     }      print(statusmessage) }  func centralmanager(_ central: cbcentralmanager, diddiscover peripheral: cbperipheral, advertisementdata: [string : any], rssi rssi: nsnumber) {     print("discovered") } } 

it printing out "turned on" not "discovered". tried multiple bluetooth devices , speakers.

you need call scanforperipherals(withservices:options:) in order discover peripherals. please note have wait cbcentralmanager in poweredon state. otherwise, nothing happen , might see warning , error logs in console.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -