I Just crate my advertisement peripheral with Service & Characteristic UUID
Here is my Service & Characteristic UUID
let kTRANSFER_SERVICE_UUID = “29ada058-c7d6-4ed5-bc7f-1c7b0458b3b8”
let kTRANSFER_CHARACTERISTIC_UUID = “91e032f2-c915-47c6-a8d9-6b3bc6c8e73d”
Now I create instance of CBPeripheralManager
private var peripheralManager: CBPeripheralManager!
private let beaconOperationsQueue = DispatchQueue(label: "beacon_operations_queue")
private let option = [CBCentralManagerScanOptionAllowDuplicatesKey:true]
// Assign peripheralManager with Queue & Option
peripheralManager = CBPeripheralManager(delegate: self, queue: beaconOperationsQueue, options: option)
Then I am calling this StartAdvertising method, But this will only work on Foreground Mode, Now I want to allow in Background Mode so for that I add the UIBackgroundModes key in Info.plist
public func startAdvertising(serviceID: String, name: String) {
let valueData = name.data(using: .utf8)
self.serviceID = CBUUID(string: serviceID)
self.peripheralName = name
let CustomChar = CBMutableCharacteristic(type: CBUUID(string: kTRANSFER_CHARACTERISTIC_UUID), properties: [.read], value: valueData, permissions: [.readable])
let myService = CBMutableService(type: self.serviceID, primary: true)
myService.characteristics = [CustomChar]
peripheralManager.add(myService)
if self.peripheralManager.isAdvertising{
self.peripheralManager.stopAdvertising()
}
peripheralManager.startAdvertising([
CBAdvertisementDataServiceUUIDsKey: [serviceID],
CBAdvertisementDataOverflowServiceUUIDsKey:[serviceID],
CBAdvertisementDataLocalNameKey: peripheralName!])
}
So when moving to the background than this will be happened
The CBAdvertisementDataLocalNameKey advertisement key is ignored, and the local name of peripheral is not advertised.
All service UUIDs contained in the value of the CBAdvertisementDataServiceUUIDsKey advertisement key are placed in a special “overflow” area; they can be discovered only by an iOS device that is explicitly scanning for them.
Also I was set “OverFlow” but still not work on background mode,
Can anyone guide for the same