4

I have an app which is working in background. I use CBPeripheralManager to Advertising and CBCentralManager to scan. I use two ıos (IOS 11.3 and IOS 13.4.1) device. First one is advertising foreground and background. Second one is scan foreground and background. I can scan;

App in the background, phone is unlocked - Works perfect

App in background, phone is locked, screen is lighted - Works perfect

App in background, phone locked, screen is off - Doesn't work!

/* I check it Advertising app which run background show in Android Device */

What is the problem. Please let me know. How can solve this problem? I want to scan both in background. My code is given bellow;

let scanOptions = [
        CBCentralManagerScanOptionAllowDuplicatesKey: NSNumber(value: true)
    ]

let services = [CBUUID(string: "e2c56db5-dffb-48d2-b060-d0f5a71096e0")]

let advertisingData = [
        CBAdvertisementDataLocalNameKey: "xxx",
        CBAdvertisementDataServiceUUIDsKey:[CBUUID(string: "e2c56db5-dffb-48d2-b060-d0f5a71096e0")]
        ] as [String : Any]

func initLocal() {

        peripheralManager = CBPeripheralManager(delegate: self, queue: nil, options: nil)
        cbCentralManager = CBCentralManager(delegate: self, queue: nil,options: nil)

    }

func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) {

        if peripheral.state == .poweredOn {
            peripheralManager.startAdvertising(advertisingData)
        }
       else if peripheral.state == .poweredOff {
            peripheralManager.stopAdvertising()
        }
    }

func centralManagerDidUpdateState(_ central: CBCentralManager) {

        if central.state == .poweredOn{

            central.scanForPeripherals(withServices: services,options:scanOptions)
            print("scanning...")

        }
        else {
            print("Bluetooth is not active")
        }
    }

func centralManager(_ central: CBCentralManager,didDiscover peripheral: CBPeripheral,advertisementData: [String : Any],
                        rssi RSSI: NSNumber)
    {

        print("RSSI   : \(RSSI)")

    }

This is my info.plist;enter image description here

uyarc
  • 579
  • 4
  • 17
  • You have already been advised that you can't use the duplicate scan key in the background. I don't see how this question is different to your previous question – Paulw11 May 09 '20 at 12:02

0 Answers0