简体   繁体   中英

applicationState is UIApplicationStateInactive in application:didReceiveRemoteNotification:fetchCompletionHandler:

When a push notification arrives, it plays audio in the background with application:didReceiveRemoteNotification:fetchCompletionHandler:.

To get it started, I press the home button, then lock screen button, then the screen is off, then send a push notification. This works when app state is UIApplicationStateBackground and I see the state by logging it to a file. Sometimes however when the app is backgrounded it mysteriously goes into the foreground right before application:didReceiveRemoteNotification:fetchCompletionHandler: and the app state is UIApplicationStateInactive in application:didReceiveRemoteNotification:fetchCompletionHandler:. Here's the log:

AppDelegate applicationDidEnterBackground: called
AppDelegate applicationWillEnterForeground: called
AppDelegate application:didReceiveRemoteNotification:fetchCompletionHandler: called. currentThread 0x174261900 isMainThread 1
AppDelegate application:didReceiveRemoteNotification:fetchCompletionHandler: applicationState == UIApplicationStateInactive

On some phones in application:didReceiveRemoteNotification:fetchCompletionHandler: it consistently shows UIApplicationStateBackground and on others it is UIApplicationStateInactive. Any idea why this happens?

In modern operating systems, background processes are either "suspended" so they can be pulled up quicker (state is UIApplicationStateBackground ) or their memory is deallocated to give memory to a more frontal process. In this case, it becomes your UIApplicationStateInactive . This happens when your device has an intense process up and needs the RAM for it.

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