I'm using UNNotificationServiceExtension
in my Swift app for iOS and it is working OK. For special cases I need to know if my app is running when the method didReceive
from UNNotificationServiceExtension
is getting called. I tried writing to UserDefaults
a bool value that indicates the app state, which is being modified by AppDelegate
events, for example setting it to false when applicationWillTerminate
is called, but sometimes app can be killed by system without calling applicationWillTerminate
, so my variable in UserDefaults
will indicate that app is still alive. Is there any better/smarter way to reach the main app state from iOS UNNotificationServiceExtension
?
如果您已经实现/覆盖didReceive
中的UNNotificationServiceExtension
在AppDelegate
话,还有你可以简单地检查这样的
let state = UIApplication.shared.applicationState
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.