1

Here is the situation :
I have an home-made beacon which advertise some more data (temperature data) than its UUID, major value, minor value. When my app is in the foreground and scan, I can get the updated temperature value (without connection). Also, I get a simple local notification (saying "Enter in beacon range!") when there is a "didEnterRegion" event (only if the app is closed).

I'd like to set the updated temperature value in this notification but I'm struggling on this. Is there anyone who already did something like this? I found only this : ibeacon-get-major-and-minor-only-looking-for-uuid but it's not helping since the values are still fixed.

Any tips?

Community
  • 1
  • 1
RemH
  • 13
  • 2
  • Did you look at the lower lever Core Bluetooth API? I think it’s possible to do anything you need there, even in the advertising phase. – zoul Oct 23 '15 at 09:49
  • How are you retrieving the additional data? Via CoreBluetooth characteristics? You can use core Bluetooth in the background – Paulw11 Oct 23 '15 at 10:04

1 Answers1

0

You can use CoreBluetooth to read advertisements both in the foreground and background. But the rules are different for various advertising types.

  • Manufacturer advertising types can only be read when an app is in the foreground. Apps do not get callbacks on iOS in the background.

  • Service advertisements can be read in both the foreground and background. These must have a Service UUID and can have additional service data included.

  • iBeacon Advertisements, which are a specific pattern of Manufacturer advertisements have data that are are blocked from being read by CoreBluetooth in both the foreground and background. Identifiers can be read by CoreLocation in the foreground and background. But they can have no additional data.

If you want to read temp data from advertisements (without connecting) in the background you have two choices:

  1. Make your beacon send a custom service advertisement, with the temperature in the service advertising data.

  2. Use iBeacon and encode the temperature data in either the major or the minor field.

davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • I already found all this informations but it was confused. Ty to make it clear :) So, since i can't get the updated data while the app isn't running, and minor/major field won't be enough for the data (too short, temperature isn't the only thing), the only way i can figure is too restart the app in background, start a scan (with CoreBluetooth), get my data then stop the app. Is that even possible? For what i know, an app can go in background only if it was in foreground before... – RemH Oct 23 '15 at 13:43
  • Yes, an app can launch itself in the background even if it has not been launched since boot by detecting an iBeacon. Aftwr that happens, your only way to read BLE data in the background at that point is the service advertisement. So you need a custom beacon that sends an iBeacon advertisement to wake in the background AND a service advertisement to send the data. – davidgyoung Oct 23 '15 at 20:23