简体   繁体   中英

What can wake up an iOS app in the background when the device is locked?

I have an iOS app that doesn't have any background mode capabilities configured on it. There is no sound, location services or bluetooth. There's also a stored authentication token in the keychain using the kSecAttrAccessible value kSecAttrAccessibleWhenUnlocked .

When the app is active it will continuously (every 20 seconds or so) try to access the keychain in order to get the authentication token to perform a network request. However, when the app is in the background on a locked device I can see (in our remote logging system) that the app attempts to open the keychain anyways after about 5-8 hours. Ie something has woken up the app.

I see that we get -25308 errSecInteractionNotAllowed from the keychain, that UIApplication.shared.applicationState is background and that UIApplication.shared.isProtectedDataAvailable returns false (ie device is locked).

As I see iOS14.8.1 in the logs too, it cannot be the prewarming feature that Apple released in iOS15. Any thoughts on what can wake up the app like this?

I think you're looking at this wrong. It doesn't really matter why the app is being awakened in the background. Lots of things that you configure can do that; for example, receiving a notification, receiving a location during location monitoring, etc. One can even imagine that the system might arbitrarily awaken your app in the background, for any number of reasons.

Your job is simply to behave coherently. Do not assume that the app can't be awakened in the background. If whether the app is in the background or not matters for something you do, then, just as you are doing, check UIApplication.shared.applicationState and don't do it if it isn't appropriate under these conditions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM