My app act as a beacon but I want to add its local name like my appName. I want to know that can we advertise custom packet in which I can add local name while advertising major, minior, proximityuuid, and identifier in Swift.

My current code for advertiseing ibeacon:

    func initLocalBeacon() {
        if localBeacon != nil {
            stopLocalBeacon()
        }
        let uuid = UUID(uuidString: localBeaconUUID)!
        localBeacon = CLBeaconRegion(uuid: uuid, major: localBeaconMajor, minor: localBeaconMinor, identifier: identifier)
        beaconPeripheralData = localBeacon.peripheralData(withMeasuredPower: nil)
        
        peripheralManager = CBPeripheralManager(delegate: self, queue: nil, options: nil)
    }
    
    func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) {
        if peripheral.state == .poweredOn {
            peripheralManager.startAdvertising(beaconPeripheralData as? [String: Any])
        }
        else if peripheral.state == .poweredOff {
            peripheralManager.stopAdvertising()
        }
    }

I am trying to add custom packet in which I add local name for my beacon. Is it possible?

1

There are 1 best solutions below

0
On

Yor app has very limited control over BLE advertisements on iOS because it is a shared resource across all apps.

Here’s what an app can do:

  • Trigger an iBeacon advert while it is in the foreground. You only control a 16 byte UUID a 2 byte major and a 2 byte minor.
  • Trigger a 16-byte service UUID advert while in the foreground.
  • Trigger a number of bits in a 128 bit bit mask to be turned on in an Overflow Area advert while your app is in the background.

Here is what the phone (not your app) can do:

  • Trigger a scan response packet containing the name of the phone. This is automatic by the operating system and the name is the name of the phone in Settings.

Your app cannot change the advertised name in the scan response. It cannot advertise additional data over BLE other than shown above, giving you a limited number of bytes to work with.