I'm building an app in iOS that will need to detect when the battery reaches a low level to send a notification. When the app is running this is simple, just by listening for the UIDeviceBatteryLevelDidChangeNotification
notification and inspecting the current battery level. However, is it possible to receive this type of notification when the app is closed in iOS? Something similar to Android, that could fire a notification by a running service or alarm without the app opened.
I was thinking that maybe I could fire a local notification periodically to inspect the battery level, but the notification should only appear if the low level is reached. Is that a good approach, or is there a better one?
No, unfortunately this isn't possible.
NSNotifications (such as UIDeviceBatteryLevelDidChangeNotification) are not delivered to your app while it's suspended.
You can use one of the background modes in iOS, however it would be a bit of a hack as none of them are intended to be used in that fashion.
I'm thinking, maybe you could run a check on receiving a remote notification, if you can find a legitimate use for them in your app.