Advertising with iBeacon when app is in background - ios

I have been digging all forums and tutorials about transmitting in background mode with iBeacon. Until now, I couldn't find something solid which can help me. My app can successfully receive and transmit but when I press home button, transmitting stops and connection on other device/devices disappear. In myApp.plist, I added required keys but still nothing works. The question is, how can I make my app keep transmitting in background mode?

iBeacon will not advertise (transmit) in the background. If you need this you will not be able to use iBeacon and will instead need to implement your own BTLE advertisement (which will run in the background).

Related

ios app, running accelerometer while the app is in the background

I have an app using accelerometer. When a certain motion is detected, i am trying to make my iphone vibrate. While the app is in the foreground, and I conduct a certain motion, it vibrates. But it does not when the app is in the background.
I have a counter that detects this motion. When I execute this motion while in the background for three times, although it does not emit any vibration, after I transition back to foreground, the counter is increased by three. So I know the accelerometer is working. Or is putting the motions in a queue and executing it when the app comes back to foreground.
And I'm not making a rookie mistake by touching the phone's vibrate to off.
I'm quite not sure where to go from here. Is iphone inherently not capable of capturing and processing accelerometer data while in the background? Or is there something I'm not doing correctly?
In iOS there are only a certain type of activities allowed in background. Here you can check them: Background Modes.
I'm currently working in an app that uses sensors like the accelerometer and I get updates from it using the CoreLocation delegate method didUpdateLocation, since using the GPS to locate the device is one of the Apple allowed background modes. I hope this helps you!

BLE CoreBluetooth in Background, what I am authorized to do?

I've designed a very simple wearable BLE device with one physical button. This device has a UART Service and can notify a connected device when the value change (when the button is pressed).
My goal: The smartphone must be able to send an HTTP request in background every time the button is pressed. even when the app is not running.
For this need, I have to implement the iOS Bluetooth background process with CoreBluetooth. But before, i would like to know if CoreBluetooth can meet my need.
So my questions are:
Is it technically possible to keep a long-term background connection between Smartphone and BLE device, even if the Smartphone reboot.
Can I wake up or start my app in foreground (without notification) when the BLE device button is pressed.
And if the previous statement is not possible, can I execute a very basic HTTP request in background when the user press the button ?
Thank you for your help!

How to send battery updates to LE accessory from app in background when iPhone operate in peripheral mode?

I'm developing a BLE enabled App. In my App iPhone operate in peripheral mode with Bluetooth accessories. Everything works fine until I go to background Mode Because my Phone is working as peripheral so It also update accessory with battery level it doesn't work in background because app will only wakeup once accessory will send request because its already subscribe for the update I somehow have to wakeup my app in background mode and send update let's say every x minutes .
I have already enable Bluetooth LE accessory background mode.
Apparently enabling background mode only gives the 'right' to run in the background whenever there is an event triggered.
One of the method is what you already did by 'polling' from the accessories periodically by sending request to wake up the app and execute the task.
Another way is to use background refresh. The only downside of background refresh is the event will not occur at specific period. It was mentioned at about 10-15mins typically or it might tag along with other app background wake up. If the update is not very frequent or crucial, this method would probably better for your case.
You can keep your app running in background by setting the "required background modes" option in your plist. Select "App communicate with accessory".
Please see the attached image for reference

iOS:how schedule the app from background to foreground

I am coding for connection between iPhone and my smart watch by bluetooth low energy. The functionality is "find my phone", touching the watch then iPhone will alarm. During the process, I want to my app will being active. It can be scheduled to the foreground from the background, so we can do more other thing! But I am not able to find the api about it, anyone can help me, thanks?
You can not force an application to bring it to foreground.
Please see this answer for help.
https://stackoverflow.com/a/22930371/1891327

CoreBluetooth - centralManagers method didDiscoverPeripheral becomes least frequent to nothing in sleep mode

I am using CoreBluetooth and the callback method didDiscoverPeripheral gets called frequently when the app is foregrounded or backgrounded or the device is locked with device screen still turned on.
But as soon as the screen is turned off / blacked out (Sleep mode) its callback frequency is reduced to almost nothing.
What might be causing this? The device battery is full and Bluetooth turned on.
Please help me with this issue.
Thanks.
Two main things you should be aware of regarding CoreBluetooth and background operation:
1.) The CBCentralManagerScanOptionAllowDuplicatesKeyflag is ignored after an app is put into the background. If you saw a peripheral while in the foreground, you will not get another didDiscover callback for that same peripheral in the background (during the same scanning period). You can test this by having your peripheral powered off, and only powering on after your central has been sitting in the background for some time. You should then receive the callback.
2.) The other issue is that callback time for peripheral discovery is throttled down in the when in background. If for example, you would discover a peripheral in 1 second in the foreground. It could take as long as 60 seconds to discover that same peripheral in the background.
I was unable to find any direct answers as to why the iOS behaves this way. Although I have found an alternative way to resolve this.
I am implementing a PeripheralManager along with the CentralManager. That way even though the iOS device's screen is turned off, i have control of the iOS device.
tdevoy is correct, however, I would give slightly more optimistic time-to-discovery values. In my experience it requires only 1-2 seconds for discovery when either one or both devices are in the backgrounded/suspended state.
If you are not receiving callbacks when your app is in the background then there is a good chance your code is slightly wrong. In the WWDC 2013 CoreBluetooth video the engineers provide explicit instructions about how to achieve the behavior you desire. Once you are able to receive the callbacks you could schedule and present a UILocalNotification which would give similar behavior as receiving a text message.

Resources