1

I am developing an iOS application which works both in background and foreground. Everything works fine when the application is in foreground state but whenever the application is in background state and central manager is scanning for peripherals with custom UUID it doesn't call the didDiscoverPeripheral method and as soon as my application comes in foreground peripheral gets discovered.

Shared.sharedInstance.centralManager?.scanForPeripherals(withServices: [serviceUUID], options:[CBCentralManagerScanOptionAllowDuplicatesKey:true])

I am scanning with service UUID as described in apple's documentation to scan for peripherals in background. Enable Bluetooth specific keys inside "Project -> Target -> Capabilities".

Application is registered to work in background.

Getting service UUID inside scan response from device as follows :-

▿ 3 elements
  ▿ 0 : 2 elements
    - .0 : "kCBAdvDataIsConnectable"
    - .1 : 1
  ▿ 1 : 2 elements
    - .0 : "kCBAdvDataServiceUUIDs"
    ▿ .1 : 1 element
      - 0 : 6E02
  ▿ 2 : 2 elements
    - .0 : "kCBAdvDataLocalName"
    - .1 : Local Name 

Any help would be appreciated.

Varun Kumar
  • 344
  • 2
  • 24
Himanshu
  • 2,832
  • 4
  • 23
  • 51
  • You can't use the allow duplicates key in the background, but I don't believe that this would prevent discover at all; it simply means you will only get notified about the initial discovery. Discovery on the background is much slower, especially if he device is locked. How lob have you waited for discovery to occur? What object implements the delegate methods? Your singleton? – Paulw11 Feb 07 '17 at 19:18
  • I know that in background allow duplicate option is ignored. My only concern is that my peripheral is advertising the service uuid in scan response rather than advertising data of device. – Himanshu Feb 08 '17 at 04:42
  • iOS will use the scan response data to obtain additional information, but in order to be discovered in the background your peripheral must advertise the primary service in a `ADV_IND` `ADV_NOCONN_IND` or `ADV_SCAN_IND` PDU https://developer.apple.com/hardwaredrivers/BluetoothDesignGuidelines.pdf – Paulw11 Feb 08 '17 at 06:25

0 Answers0