Problem with CBPeripheralManager.isAdvertising

Hi everyone!


I was trying to turn my iPhone into an iBeacon with the following method:

https://developer.apple.com/documentation/corelocation/turning_an_ios_device_into_an_ibeacon


and also added the following line after the startAdvertising method:

  func advertiseDevice(region : CLBeaconRegion) {
      
        let peripheral = CBPeripheralManager(delegate: self, queue: nil)
      
        let peripheralData = region.peripheralData(withMeasuredPower: nil)
      
        peripheral.startAdvertising(((peripheralData as NSDictionary) as! [String : Any]))
        print(peripheral.isAdvertising)
      
    }

print(peripheralManager.isAdvertising)


but I always get false as a result, even if the beacon and the startAdvertsing is working fine.


Has somebody a explanation for that behavior ?


Thank you!

There's a delegate method you need to implement that gets called when the system starts advertising it, because it's not immediate:



peripheralManagerDidStartAdvertising(_ peripheral: CBPeripheralManager, error: Error?)

That's my mistake. Thank you !

Problem with CBPeripheralManager.isAdvertising
 
 
Q