0

I know that an iBeacon cannot broadcast/advertise in the background and I also know that its not possible for both the central and the peripheral to be in the background and discover each other. What I want to do is broadcast while in the background so that the central can discover the app while in the foreground. I'm sorry if I'm not explaining this well, please ask for clarification if I'm not clear.

I read here that "apps preform differently when running in the background as opposed to the foreground". On page 37-38 it describes what is different in the background for peripherals. It mentions "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." What is an overflow area and how do you explicitly search for the device? All I need is the major/minor values and the RSSI. I don't want to connect to the peripheral, I just want to interact with it as if it were an iBeacon.

Also, I need to be able to discover multiple devices (all with the same UUID) but all with unique major/minor values.

Here's my code:

var locationManager: CLLocationManager!
var beaconRegion: CLBeaconRegion!
var centralManager: CBCentralManager!

override func viewDidLoad() {

    locationManager = CLLocationManager()
    locationManager.delegate = self
    centralManager.delegate = self

    let majorVal: CLBeaconMajorValue = 123
    let minorVal: CLBeaconMinorValue = 456

    let uuid = NSUUID(UUIDString: "00000000-0000-0000-0000-000000000000")
    beaconRegion = CLBeaconRegion(proximityUUID: uuid,identifier: "beacon")

    locationManager.startRangingBeaconsInRegion(beaconRegion)
    locationManager.startUpdatingLocation()
}

Then I just handle the distance to the beacon and record it's major/minor values.

This question is very similar to mine; the only difference is he wanted both devices to work in the background and I only need the peripheral to work in the background not the central.

How do I broadcast in the background and then discover in the foreground?

Thanks for your help!

Community
  • 1
  • 1
Jake
  • 319
  • 1
  • 7
  • 21
  • You can't use a beacon region - that is for iBeacons. You will need to use CBPeripheralManager (to advertise) and CBCentralManager to scan. – Paulw11 Aug 13 '15 at 01:54
  • In your case the service UUID will be the equivalent to your beacon UUID - all devices can advertise the same service. Your Central will then scan for this service. – Paulw11 Aug 13 '15 at 02:10
  • @Paulw11 would the CBPeripheralManager continue to advertise even in the background? And do I have to do anything special to scan for them or is it the same? – Jake Aug 13 '15 at 04:22
  • Yes, it would - as described in the Core Bluetooth programming guide. Scanning is the same, except that you must specify a service (you can't use nil) and you can't use the duplicates scan option – Paulw11 Aug 13 '15 at 04:32
  • @Paulw11 sorry, but would you mind telling me or showing me what that looks like? Or where to find that in the programming guide? Thank you so much for your help. – Jake Aug 13 '15 at 04:34

1 Answers1

0

Unfortunately, you cannot do this. Two things prevent this from working:

  1. An app advertising as an an iBeacon and scanning for other iBeacons will not detect its own transmission. This is not an iOS thing, it is a Bluetooth thing. Bluetooth scans do not detect advertisements originating from the same device.

  2. If you transmit an iBeacon advertisement from an app in the background, it breaks the advertisement format so it no longer is recognizable as an iBeacon transmission. This is caused by the same iOS functionality that moves service uuids to the "overflow area" when in the background. See here for more info.

Community
  • 1
  • 1
davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • Sorry for not being clear. I'm not looking to broadcast and search from the same device. Two separate devices running my app. The one in the background would not be searching and the one in the foreground would. Is it not possible to broadcast in the background? – Jake Aug 13 '15 at 04:21
  • It doesn't need to be an iBeacon transmission. My example is an iBeacon transmission only because I don't know how to do anything else. – Jake Aug 21 '15 at 22:06