BLE Scanning in background State of iOS app - ios

There is any API OR third party for BLE communication in iOS app background state ..?I tried “Uses Bluetooth LE accessories” ,”Background Processing”,”Background fetch” with these capabilities BL Scanning is working but Advertisement data packet decrease .In app foreground state advertisement data packet increase ..how can I get maximum quantity of advertisement data packets.? I am using service UUID for Scanning.

As Rob Napier said, scanning in the background state as aggressively as in the foreground state is impossible by design because the system has lower resources and is attempting to save power. This is detailed in Apple's Core Bluetooth Programming Guide:-
For iOS apps, it is crucial to know whether your app is running in the
foreground or the background. An app must behave differently in the
background than in the foreground, because system resources are more
limited on iOS devices.
Although you can perform many Bluetooth-related tasks while your app
is in the background, keep in mind that scanning for peripherals while
your app is in the background operates differently than when your app
is in the foreground. In particular, when your app is scanning for
device while in the background:
The CBCentralManagerScanOptionAllowDuplicatesKey scan option key is ignored, and multiple discoveries of an advertising peripheral are
coalesced into a single discovery event.
If all apps that are scanning for peripherals are in the background, the interval at which your central device scans for advertising
packets increases. As a result, it may take longer to discover an
advertising peripheral.
These changes help minimize radio usage and improve the battery life
on your iOS device.
You can find more information here:-
CoreBluetooth background processing for iOS apps
iOS BLE scan in background
iOS - Scan and connect to a BLE peripheral in the background

Related

Background scanning not working without having last peripheral in iOS?

I trying to connect peripheral using UUID in the background, It's working only when i interact with advertising beacon first time at foreground then my app went background its working background and lock mode also if First time my app is away from advertising beacon i put my app at background then will come near to advertising beacon it's not working. in console, they came last peripheral not found as that error will come, my question is :
is this possible to scan or connect Bluetooth using UUID for the first time without the app opening?
i already tried that solutions also :
iOS BLE device paired while app is in background or killed or suspend
iOS: didDiscoverPeripheral not called in Background mode
didDiscoverPeripheral: not working sometimes on background
Not able to search my BLE Device which is providing service ID in scan Response iOS
Source file : https://drive.google.com/file/d/1uVR_kA3NsQUpM-LLgrGgXCeZK6PBO-A7/view?usp=sharing
Found this question a bit interesting, so went about studying CoreBluetooth.
As per the Core bluetooth programming guide
Although you can perform many Bluetooth-related tasks while your app is in the background, keep in mind that scanning for peripherals while your app is in the background operates differently than when your app is in the foreground. In particular, when your app is scanning for device while in the background:
The CBCentralManagerScanOptionAllowDuplicatesKey scan option key is ignored, and multiple discoveries of an advertising peripheral are coalesced into a single discovery event.
If all apps that are scanning for peripherals are in the background, the interval at which your central device scans for advertising packets increases. As a result, it may take longer to discover an advertising peripheral.
Now in your provided sample the background modes are correctly provided.
iOS looks for advertising packets only in background [Passive] mode and not the response packets
Searching further bought me to this link
ios- Scan and connect to BLE peripheral in background
You can check and see if this too is the case with you

iOS background app to read Bluetooth advertisement

Is it possible to build an iOS App that can run in the background, with minimal battery consumption, and collect BLE advertisements payloads of specific devices? Does iOS prevent such apps to work in the background even when the user has given consent?
Yes it is possible to build such an app that can continuously scan in the background. Check Apple's Documentation on the subject:-
CoreBluetooth background processing for iOS apps
Also check the following links with more details on the subject:-
BLE device keep connect with iPhone when app terminates
Leveraging background Bluetooth for a great user experience
iOS background Bluetooth: BLE scanning when phone is locked
However, there are limitations to the speed of the scan and the data retrieved from the scan. See the links below for more info:-
Scan peripheral in background
iOS: scan and connect to a BLE peripheral in the background
Overcoming the iOS background Bluetooth limitations

Can an iOS app that is acting as a BLE peripheral running in the background be woken up by a connection request from a BLE central?

I have an iOS application that is acting as a BLE peripheral. It is advertising at all times. I have a Raspberry Pi that is acting as a BLE central. It is scanning at all times. If the iOS app goes into the background and is suspended, and if the iOS app has the UIBackgroundModes key set to bluetooth-peripheral, will the app be woken up by a connection request from the central? Assume that the central and the peripheral have never connected before. Thank you!
You can advertise a peripheral in the background, but there are some limitations, which are described in the Core Bluetooth Programming Guide
The CBAdvertisementDataLocalNameKey advertisement key is ignored, and the local name of peripheral is not advertised.
All 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.
If all apps that are advertising are in the background, the frequency at which your peripheral device sends advertising packets may decrease.
The second point, in particular, may make it difficult for your RPi to discover the peripheral; I am not sure if the standard discovery process will work.

IOS Developpement : Background BLE scanning

I'm currently trying to develop a Background Bluetooth related app, and I'm having some trouble scanning in background.
I followed the entire Apple IOS Bluetooth Background tutorial, but I cant figure out why scanning doesn't work in background (my info.plist is correctly set up to manage BLE Background tasks, both central and peripheral).
What I've tested so far :
1 - When my two devices are in range and in foreground, scanning works well.
2 - When the peripheral is in background, and the central comes active in foreground, scanning also works, peripheral is well detected.
Here comes the troubles
3 - first I launch my peripheral device, and I put the app in the background. Then on the peripheral device, I power off the bluetooth, I launch the app, I put it in background, and I power on the bluetooth.
In my code, the -(void)centralManagerDidUpdateState:(CBCentralManager *)central calls the scan [centralmgr scanForPeripheralsWithServices:[NSArray arrayWithObject:servicesUUID] options:scanOptions];, function which works perfectly in the foreground. But nothing happened, the peripheral is never detected by the central.
4 - I launch the central, bluetooth activated, and I put it in background. Then I took my peripheral device, I went out of the bluetooth range (in the specific case I went to my supermarket to buy some beers to drown my sorrow), I launch it there -also bluetooth activated- I put it in background and I came back in the proximity of my peripheral. Once again nothing happened, the centrals did not detect the peripheral.
Furthermore, after the cases 3 and 4, if I just put the central on the foreground (the peripheral stays in background), detection restart, without doing anything else. As if the scan was successfully triggered in the case 4, but waiting the app to come active to actually start detecting other devices.
Does somebody have an idea on how to proceed/overcome the problem?
Thank you!
Ps: I appologize for my English, I'm a bit rusty
Hi for details you can see this answer
but the short answer is one of your Apps must be in Foreground to connect to each other
Either your central device or the peripheral
Reason: for central you an only scan with providing the service UUIDs of the peripheral
and in background a peripheral cannot adverise its UUIDs
so even they are there they just don't know of each others presence
Moreover some more notable things about background scanning are
you should be aware that advertising while your app is in the background operates differently than when your app is in the foreground. In particular, when your app is advertising while in the background:
The CBAdvertisementDataLocalNameKey advertisement key is ignored, and the local name of peripheral is not advertised.
All 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.
If all apps that are advertising are in the background, the frequency at which your peripheral device sends advertising packets may decrease.
See Apple Docs

iOS - iBeacon - Advertise (Broadcast) as beacon in Background after iOS 7.1 update

I am trying to make an Application using iBeacon in which One device will work as beacon Broadcaster and another one as Receiver.I gone through the similar thing in Run iPhone as an iBeacon in the background but the solution that present there is not for API of iBeacon so i am asking this thing again.
I succeed in being notified on Detector Device(receiver) even the App is in Background or in Quit mode. but Whenever Broadcaster Device's App goes in Background it stops Broadcasting packets and become no more as beacon. When it comes back in Foreground it again works fine. So the issue is Broadcaster has to be always in Foreground to Act as Advertiser or Broadcaster.
Is there anyway to advertise/Broadcast packets of iBeacon's even when App is in background mode.
I have enabled capabilities "Location Update" and "Acts as a Bluetooth LE accessory" from xCode.
Unfortunately, it is simply not possible to advertise as an iBeacon in the background on iOS. For an explanation as to why, see here: Can we start iBeacon transmitter in background?
Apple doesn't authorize it, it would be a mean to track an user which is quite against Apple current policy to preserve users' privacy.
The capabilities "Acts as a Bluetooth LE accessory" is to enable your application to continue being used as a bluetooth device (with a connection) when the app go in background mode. Advertising isn't a connected usage of bluetooth and isn't concerned by this capabilities.

Resources