Detect iOS device battery level when app is closed

Gio MV

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?

Woodstock

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.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Is there anyway to detect app closed on flutter?

分類Dev

how to access device battery level from lock screen

分類Dev

Detect iOS app entering background

分類Dev

iOS - CoreLocation and geofencing while app is closed

分類Dev

How to detect when keyboard is opened or closed in React Native

分類Dev

How to stop Android service when app is closed

分類Dev

How can we programmatically detect which iOS version is device running on?

分類Dev

How can a JavaScript app detect if a Leap Motion device is connected

分類Dev

Latest build of iOS app not running on device

分類Dev

Get battery level of connected smartwatches

分類Dev

Java Detect Closed Stream

分類Dev

Detect closed socket

分類Dev

Detect that SKShapedNode is closed

分類Dev

Not load video embedded with iframe when detect a mobile device

分類Dev

Detect when it is evening/night - NSDate - iOS

分類Dev

How to detect location in device's current location mode since API level < 19 (Kitkat)

分類Dev

iOS - No Graphics when testing SK game on device

分類Dev

Keep broadcast receiver running when activity and/or app is closed?

分類Dev

How to keep an IntentService running even when app is closed?

分類Dev

Push Notifications don't vibrate when app is closed

分類Dev

Keeping a Java app running when SSH is closed on Google Cloud

分類Dev

Android access battery stats or monitoring battery level through manifest

分類Dev

How to get android battery level from ubuntu?

分類Dev

Detect whether React Native iOS app was opened via push notification

分類Dev

Error while compiling iOS app with openCV framework on real device

分類Dev

Xamarin IOS app crashes only after putting on itunesconnect and physical device

分類Dev

How to run flutter app developed in AndroidStudio on iOS device?

分類Dev

calabash-ios physical device test, app starts but crashes

分類Dev

"No active iOS device found" when trying to access simulator logs

Related 関連記事

  1. 1

    Is there anyway to detect app closed on flutter?

  2. 2

    how to access device battery level from lock screen

  3. 3

    Detect iOS app entering background

  4. 4

    iOS - CoreLocation and geofencing while app is closed

  5. 5

    How to detect when keyboard is opened or closed in React Native

  6. 6

    How to stop Android service when app is closed

  7. 7

    How can we programmatically detect which iOS version is device running on?

  8. 8

    How can a JavaScript app detect if a Leap Motion device is connected

  9. 9

    Latest build of iOS app not running on device

  10. 10

    Get battery level of connected smartwatches

  11. 11

    Java Detect Closed Stream

  12. 12

    Detect closed socket

  13. 13

    Detect that SKShapedNode is closed

  14. 14

    Not load video embedded with iframe when detect a mobile device

  15. 15

    Detect when it is evening/night - NSDate - iOS

  16. 16

    How to detect location in device's current location mode since API level < 19 (Kitkat)

  17. 17

    iOS - No Graphics when testing SK game on device

  18. 18

    Keep broadcast receiver running when activity and/or app is closed?

  19. 19

    How to keep an IntentService running even when app is closed?

  20. 20

    Push Notifications don't vibrate when app is closed

  21. 21

    Keeping a Java app running when SSH is closed on Google Cloud

  22. 22

    Android access battery stats or monitoring battery level through manifest

  23. 23

    How to get android battery level from ubuntu?

  24. 24

    Detect whether React Native iOS app was opened via push notification

  25. 25

    Error while compiling iOS app with openCV framework on real device

  26. 26

    Xamarin IOS app crashes only after putting on itunesconnect and physical device

  27. 27

    How to run flutter app developed in AndroidStudio on iOS device?

  28. 28

    calabash-ios physical device test, app starts but crashes

  29. 29

    "No active iOS device found" when trying to access simulator logs

ホットタグ

アーカイブ