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

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

Related

How to do a request in background each 5 minutes in iOS

I have an iOS application that communicate with an IoT gadget
And now I need a to do a request for an API each 5 minutes when the iOS app enters in background
I know this is horrible for battery consuming but in this specific case this is irrelevant since my iPhone device will always be connected to charger, and I won’t need this app in the store, so the apple politics is not a problem too
I already tried use Timer and TimerInterval, with the background state activated but none of then execute after the time I defined
Has any way to do this ?
Edit: I all my attempts I already activated background fetch, background music and all background modes
First you need to start background mode in your project. It looks like this:
To get to the background modes capability list you:
Select the project from the Project navigator.
Click the app target.
Select the Capabilities tab.
Turn the Background Modes switch on.
If you want to perform background task then select it from capability.
For more clarity for background fetch you can check below link
https://www.ioscreator.com/tutorials/background-fetch-ios-tutorial

iOS - What does External accessory communication of Background Modes do?

I guess it is a background mode related to ExternalAccessory.framework.
But the document about External Accessory says, "If your app is suspended in the background when an accessory notification arrives, that notification is put in a queue. When your app begins running again (either in the foreground or background), notifications in the queue are delivered to your app. Notifications are also coalesced and filtered wherever possible to eliminate any irrelevant events. For example, if an accessory was connected and subsequently disconnected while your app was suspended, your app would ultimately not receive any indication that such events took place.".
This means that the external accessory communication will be just queued until the app enters foreground mode, But the other background modes like Location, Bluetooth LE are working as real-time in background mode. So I doubt that just queued is the only thing that can do. Is it really?
If your external device is "Made for iPhone/iPod/iPad" - MFi you can use this option. It's not for BLE communication.

How to get screen lock/unlock events on the iPhone when app is suspended?

I have a requirement where i need to track the iphone device state like if device is locked or unlocked. I was able to track these events when the app is running in foreground or background. But i also need to track the same when the app is suspended. Something like tracking the user location in background when the app is suspended. But i don't need to track the user location but only the device state.
Please suggest me some steps to solve this issue in objective-c.Thanks in advance.
You can not perform any operations once your app is in suspended state and you can not prevent your app from getting suspended unless you are using one of the background capability mode mentioned in this apple doc
So what you are looking for is not possible if you are not using either of background modes allowed by apple.
EDIT
Even if you go on and enable one of background mode like background audio, your app is likely to be rejected during review process as reviewer will see you do not have a valid reason to use that particular background mode.

Understanding the `backgroundRefreshStatus` property

I've an iOS app enabled for updating locations in Background Mode. I'm listening for the UIApplicationBackgroundRefreshStatusDidChangeNotification notification, and checking the backgroundRefreshStatus property. About the property, it is said in the documentation:
This property reflects whether the app can be launched into the background to handle background behaviors, such as processing background location updates and performing background fetches.
I made some tests running the app in the simulator and, when I disable the "Background App Refresh" feature for the app in "Settings", I do receive the notification of the status change, but I see that locations keep being updated. I expected all background tasks to stop when "Background App Refresh" disabled by user... is that a simulator concern/bug? Or is the developer's responsibility to stop the background tasks anyway?
Thanks

IOS corebluetooth Background mode notification

Currently am working with the project using core bluetooth. In which am using background mode communication, am able to receive the notification when ever app running in background but we have only one service and one characteristics for data communication based on frame type we are able to identify the frames which is received.
For background mode i used this code
[centralManager connectPeripheral:activePeripheral options:#{CBConnectPeripheralOptionNotifyOnConnectionKey: #YES,
CBConnectPeripheralOptionNotifyOnDisconnectionKey: #YES,
CBConnectPeripheralOptionNotifyOnNotificationKey: #YES}];
its working fine for both event and session background.
Event background alert shows for every notification is there any way to hide the alert for every notification show only needed.
Thanks
In event mode the alerts are generated by the system and as long as your app is not activated, it can't do anything about them.
In session mode the app stays responsible for handling all these events. It receives all the callbacks just as in the foreground. If you want to minimize the disturbance of the user, you should take over the alert generation with this mode.

Resources