Prevent iOS app to terminate or relaunch when running on backgroud for long time - ios

I've developed an iOS app that connects to a BLE peripheral and retrieves heart rate data of one person during the night.
The app runs on the foreground and also on background using Bluetooth accessories background mode.
It receives heart rate data every second and appends it into a file, in order to save a report for the whole night.
The app is working fine in some devices (it writes data during the whole night), but in other devices (tested an iPhone 5s) it relaunches automatically every 1.5 or 2 hours. I found that sometimes iOS kills background apps due to memory pressure, so I made some memory tests with the profiler, but the app only consumes 8MB, and it never gets more than that, so there is no memory issue.
It is really important for me to prevent the app suspending, so I can detect any possible anomaly on the heart rate and trigger an alert.
Any clue on this?

Related

How to deliver a BLE message to an iOS app that isn’t running?

I am working on a device that sends a message/signal to an iOS app via BLE. It currently works fine if the app is running in the foreground or background; however, I need the device to deliver this signal to the app when it isn’t running so it can process it, in essence, “waking it up.”
A device that seems to be doing this well is Tile (used to keep track of keys, etc.). The Tile can signal the phone even when the Tile app isn’t running, making the Tile app come up and sound an alarm. My use case isn’t the same, but I need to achieve the same behavior.
Does anyone have any pointers as to how to achieve this? The OS needs to launch/wake the app upon receiving this BLE message/signal from my device.

ios ble data lost after being killed in background mode

I have an iPhone app that receive BLE info from a particular device. The device sends data to my app anytime it has something to report, and the transmission rate is about 2K Bytes per second.
The problem is that my app can be killed in the background mode by iOS and I can get no indication about this. If the device start to send ble data after my app is killed, my app can only get the last data packet after it is woken up by the system and lost all the data during the wake up procedure.
How can I get all the BLE data after my app is woken up and restored by the system?
PS: I have added Bluetooth-central under UIBackgroundModes in the Info.plist. In background mode didUpdateValueForCharacteristic: method is being called. Also, a CBCentralManagerOptionRestoreIdentifierKey is specified while I construct the CBCentralManager.
On iOS you can ensure that your app isn't completely killed by the system by using State Preservation and Restoration. Please have a look at the following link for more info:-
Core Bluetooth Background Processing for iOS
However, please note that you cannot use this if you force kill the app. There's more information about this in the following question:-
BLE device keep connect with iPhone when application terminate

BLE device- same code and same firmware works well with iphone SE and works not as good in iphone 7 plus

I am working with ibeacon. I created an application for tracking devices. But I am facing a problem with the application. The app works well in the terminated state for iPhone SE whereas it is not working (in the locked state) for iPhone 7+.In the unlocked state it is working for 7+ also but still it is very slow compared to iPhone SE. Is there any specific reason for this problem. If it can be solved, what could be the possible solution to this problem.
I am really helpless and clueless about this issue.Please do help me and assist me with your knowledge Sir. Thank you in advance.
When an iOS app is in the background, it relies on two different mechanisms to detect beacons:
Hardware filters. These are byte patterns stored on the Bluetooth chip that alert the OS when a BLE advertising packet is received that matches your beacon region. This mechanism is very fast and delivers results within a second, but it is a limited resource. Once all slots are full, it will no longer work. There is no documentation about the number of slots available on each iPhone model, but experiments suggest the number is ~30.
Software scans. A full BLE scan is performed to find all beacons even if they are not stored in a hardware filter. In the foreground with ranging active, software scans are constant. In the background they are periodic to save battery, so detections based on software scans are much slower. The rate is undocumented, but experiments suggest software scans are performed every ~10 minutes in the background in the typical phone state. An additiona softwarel scan is also performed when the screen is unlocked.
The problem description is consistent with hardware filters (1) not working on the iPhone 7+. This may not be a problem with the phone model, it could be a problem with the specific device, or more likely the software state on the phone. A typical cause is the installation of multiple beacon apps that use up all the slots. Each beacon app can register up to 20 beacon regions for monitoring, so just two apps could use up all the slots!. The first apps to run and register slots may hold them forever.
A few troubleshooting tips:
Uninstall any other apps you think may. be detecting beacons, then re-install yours.
Restart your device.
If the above does not help, you may have a hardware problem with your device. Try another iPhone 7+ to see if you can reproduce.

iOS background service using BLE after reboot

I'm new to mobile development, before eventually deciding where to develop (android/ iOS) a specific application I have a question (I'd prefer using an iPhone):
So the background is that I have a BLE device frequently sending data to the phone and let the phone app sync the data to the cloud. Now, it is really important that if for some reason the phone has to restart, it will automatically proceed receiving the BLE data.
Is it possible at all in iOS to start a background process (handling BLE packets) after reboot automatically. Thus e.g. when the respective BLE device pairs to the phone after a reboot, that the background process starts automatically, without the user having to start the app manually?
Doing some research I came up with mixed results regarding this scenario and would be grateful if someone with iOS experience could clarify.
(BTW: It does not have to be an Apple App Store Application)
A Few days ago I was working on BLE devices Beacons we supposed to make mobile application and start monitoring these beacons and send date monitoring to API.
This works fine in background, even the user was not running the application in foreground or reboot his iPhone.
All we should do is put the monitoring code at the appDelegate of the application to work in the background.

Can I communicate with a slave BLE even if app is not running?

I am developing an iOS application that communicates with a slave BLE device. I know iOS will allow my app to run in background to communicate with BLE. What my doubt is that is there any way to turn on my app if there is any BLE near by? I mean even if my app is not running can I communicate with BLE? Like location service works,i.e., if the app registered for a significant location change alert then app will get automatically turned on when there is a significant location change even if app is not running.
I have searched a lot, but couldn't find any helpful documentation. Any help is greatly appreciated..
There are a few things here and I think you have to be careful with terminology. Let's first clarify "Not running". The app has 5 modes it can be in:
Foreground: the app is "live" and on the screen
Background - unlocked: the app is "live" but not on the screen. There is either another app on the screen (front) or possibly the user is on the home screen, browsing his/her apps, etc..
Background - locked: self explanatory
Terminated by user - still on device: The user has double clicked the home button and flicked your app up (iOS7) to close it.
Terminated by system - still on device: The app has been terminated by OS because of memory pressure (other apps needed the memory space).
Obviously, if the user has deleted the app from the device then there is nothing to discuss.
In option 4, the app is still on the device but will not relaunch any of its background services (BLE, location updates, etc..) until the user relaunches the app. This is new iOS7 behavior. If the user terminated the app then he/she does not want it running.
In option 5, because the user has not terminated the app; the OS will relaunch the app background services as it receives callbacks.
In order for an app to run in the background, it requires that you add the appropriate background modes to its plist or simply click on project (top left) and go to "Capabilities" and enable "Background modes" and the appropriate background mode. In your case: "Uses Bluetooth LE Accessories".
Now you seem to be looking for "Scanning" versus connecting and exchanging data and in my experience, scanning will only work in scenarios 1 and 2 and 5. Not 3. I have tried many times to get scanning to happen while phone is locked with no luck.
Now the way, fitbit etc... work in the background is that the app, scans, discovers services and characteristics and "setup updates" between the phone and accessory while the app is in the foreground. Once this setup is done, the "value of interest" updates (heart beat, etc..) can happen between the BLE acessory and the iOS device, in the background (locked and unlocked).
Hope this helps.

Resources