CoreBluetooth and iBeacon: any conflicts? - ios

I have got a chip that has a iBeacon service as well as a standard BLE service.
I would like to use the iBeacon service to trigger the app that I am developing when entering a BLE signal range.
Once active I'd like the app to scan for peripherals using CoreBluetooth and then connect to the chip.
Is this against Apple terms and conditions?

Apple has no known restrictions on this setup. In fact, this is how the RadBeacon configuration app works.
Using this technique, detecting a beacon in the background will only give your app 5 seconds of background running time, which generally is not enough time to reliably complete Bluetooth pairing and data exchange. Your best bet would be to present a local notification to the user on beacon detection, and then if the user brings the app to the foreground, do the pairing.
An alternative would be to extend background running time using a technique like described in my blog post here. That post shows how to range for beacons in the background, but the same technique will work for bluetooth communication tasks.

Related

iOS omits manufacturer data from advertisement in background mode

I work on iOS application which is using BLE for communication with our custom made BLE unit.
We want to send specific commands via BLE to the unit automatically.
When user is near unit and specific criteria are met, the app should connect to the unit, "login" the user, send command via BLE and disconnect right away.
These specific criteria are based on manufacturer data from advertisement (i.e. the unit is in "available to login" state when manufacturer data has last byte 0x01, when it's "NOT available to login", last byte is 0x00).
In foreground, this mechanism works flawlessly.
We want to do this even when app is in background or terminated (swipe up in dashboard on iPhone).
The mechanism we have implemented:
the unit has capability of acting as iBeacon
when unit is NOT available for login, the iBeacon is OFF
when it IS available for login, the iBeacon will turn ON and wakes up application, upon that the BLE scan will start in background mode
background mode setting is bluetooth-central
Problem here is that no matter what I tried, the advertisement:
sometimes it's not discovered at all (looks like it's timing issue?)
when it's discovered, it does NOT contain manufacturer data
Did anyone come across something similar?
Any help is appreciated and have a nice day!
An app simply cannot read raw BLE manufacturer advertisement data when in the background on iOS -- the operating system prohibits it.
Two exceptions to this rule:
iBeacon, which itself is implemented as a specific type of manufacturer advertisement. An app can detect iBeacons in the background on iOS, although only four bytes of readable data (encoded in the major and minor fields) are fully usable. If you can modify your device to send information this way, it will do what you want. However you must use CoreLocation APIs to detect iBeacon, as CoreBluetooth does not allow reading manufacturer data from iBeacon advertisements. If you do use CoreLocation, you cannot use the detections to establish a Bluetooth connection with CoreBluetooth as the two APIs are sandboxed.
Overflow Area advertisements. Backgrounded iOS apps can read these special types of manufacturer advertisements when in the background but only if the screen is turned on. (It is often possible to force the screen on at specific times by sending a local notification.) See my blog post here for more info: http://www.davidgyoungtech.com/2020/05/07/hacking-the-overflow-area
An alternative to detecting manufacturer advertisements is to use BLE Service advertisements with attached data. For this to work, you'd need to define a 16 bit or 128 bit GATT Service UUID and send out an advert with attached data bytes. Eddystone beacon formats work this way, and allow detection in the background on iOS. This is probably the best approach if you can alter the BLE hardware.

iOS advertising beacon in background

I devlope advertising data app in iOS.
My app advertising data is good in foreground.
But I want to advertising beacon data in ios background.
I set up background-peripheral setting.
and advertisingData
advertisingData = [CBAdvertisementDataLocalNameKey: localName,
CBAdvertisementDataServiceUUIDsKey: [serviceUUID]]`
that's well show foreground
when, my app stopped(home button), ios beacon scanned,
but all data not showing.
I already know in background mode, services gone `overflow' area,
but is there anything you can do without a offical way?
I wrote my master thesis about this topic. The answer is no, it is not possible to make an iOS App advertise beacon data in background.
It doesn't work with the traditional CoreLocation APIs. What you may be able to do, is to replicate the iBeacon behavior in your app while supporting background broadcast and detection, but I did not manage to make the broadcasted signal to be recognised as a beacon.
Check this answer for additional information:
https://stackoverflow.com/a/19941436/3726570

iBeacons and CBService Broadcast simultaneously

Is it possible to simultaneously broadcast my iOS app as an iBeacon and at the same time publish a service?
My app currently advertises a service, which works perfectly fine. My client app (central) is able to find the peripheral, connect, obtain the service and read data from the characteristic. However, if I update my server app (peripheral) to start broadcasting as an iBeacon emitter in addition to the service, I am no longer able to find services that I setup to advertise on the client app (central).
The idea of this is that I want to be able to read information from the server (peripheral) app when in close proximity from the client (central).
Is this technically feasible?
I was thinking about turning off iBeacon transmission when a device comes into close proximity and then starting the service broadcast, but there is no API in Core Bluetooth that calls back to the emitter when a client device enters the region being advertised.
Is this doable? Is there a workaround that would achieve something along these lines? I would like to avoid any networking, as this should be an offline solution.
Taz, For sure you can be an iBeacon and you can look for iBeacons. What I did and what I see other doing is combining iBeacons with other services, such as the CloudKit [which yes, means networking too] to add functionality to their basic functionality.
That said I can imagine an app in which your iBeacons switch to a different protocol when they see each other, the challenge; how-to negotiate a channel/UUIDs for a BLE peripheral/central pair.
I am still in the process of building, but have implemented something similar over the past months... in short you hardcode an initial channel to start your BLE conversation, your first and only exchange on said channel being to agree a new BLE one to use.

Mi Band 1S vibration on incoming call handling on iOS

SO. Initial data:
Device Xiaomi Mi Band 1 or 1S
Device paired with iPhone
Xiaomi iOS app has option "Vibrate on incoming calls"
How they implement it? It continue works if you reboot device or force quit an app. It is unusual for default BLE background. Any ideas how this app handle events?
For people who vote for closing this question. This is a very interesting issue which require some specific knowledge about bluetooth and background. For example there are three bluetooth background modes: external-accessory for old-school non-ble blueooth, bluetooth-central and bluetooth-peripheral. I have done a lot of experiments about last two. But it does not work as you expected after documentation reading. I have found few questions about this topic here on SO. All of them report about pure predictable for bluetooth background. And after all hours on this issue you see on Mi Band and them official absolutely legal app in App Store. And this App keeps connection or has some other "magic" mechanism to handle calls and initiate reaction on device. At a minimum it is curious. Is it? At a minimum it is useful for developers who works with peripheral devices.
It looks like Apple Notification Center Service (ANCS) integration, not Bluetooth Background + Core Telephony.
The purpose of the Apple Notification Center Service (ANCS) is to give Bluetooth accessories (that connect to iOS devices through a Bluetooth low-energy link) a simple and convenient way to access many kinds of notifications that are generated on iOS devices.
Documentation
CategoryIDIncomingCall is about incoming call

iOS: detect app users nearby

I want to build and app which can detect other iPhones with my app within 65 feet range. As I understand I have the following choices:
Use Bluetooth to check periodically whether there is device with my app in the range. Send list of found devices to the server. The problem here is battery consumption. Is it true that Bluetooth will be disabled after some period of time automatically?
Can I use BLE technology for this purpose? If so, do you know what devices support BLE?
What is the best option on your opinion? Did I miss some other option?
Thanks
UPDATE
I plan to run search every 20 seconds or even more often.
There is no simple answer to this problem.
Bluetooth has 2 flavors: "Regular" bluetooth, used for hands-free devices, headphones, and the like, and BLE (Bluetooth Low Energy)
Regular bluetooth devices must be paired. (I'm less familiar with regular bluetooth than BLE, so take my explanation of this bit with a grain of salt.) In order to be paired they have to be put into "discoverable" mode, which broadcasts their ID. That is a battery-draining and only done briefly. It's not an "always on" solution.
BLE has a range of up to 60 meters, so it should meet your need in that regard.
BLE devices can "advertise" as a "peripheral" for extended periods. Other Bluetooth devices can act as a "central" and ask to be notified when certain peripheral devices are detected. I'm not sure if you can make an iOS device advertise (broadcast) as a BLE peripheral while it's in the background and/or if the device is locked, but it will certainly advertise while it's running. I'm pretty sure you can register to be notified when you detect a certain BLE peripheral from the background, but not positive.
iBeacons are a specific use of BLE with some extra limitations and some extra abilities. An iBeacon is a dirt-simple transmitter that sends a UUID plus a major and minor value and a signal strength calibration value periodically (usually once a second.) You can't add any other data to an iBeacon transmission. iOS can only act as an iBeacon transmitter when the app is in the foreground. If your app moves to the background, it stops transmitting. Period.
However, you can listen for iBeacon signals even from the background. AND, if you've registered as a listener for an iBeacon and the system terminates your app due to low memory, the system still listens for those beacons on your behalf. If iOS detects a beacon you're listening for, you get re-launched if needed, and notified in the background. You can then post a local notification to get the user's attention.
iBeacons are probably your best bet, but you will need your users to be actively running your app in the foreground in order to transmit a signal. That will drain your user's battery fairly quickly.
One possible solution would to have have every single device send their locations to your server every predetermined time period (more frequent the better but more resource intensive). Then, query the data from the server and get the location of all the devices near you.
Keep in mind, that this probably won't be very useful for real-time data collection. For example, if you want to send data every 30 seconds or so, this isn't a good option.
Use this option if you want to get data every 15-20 minutes or so.

Resources