2

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?

inthy
  • 362
  • 6
  • 16

1 Answers1

-2

if you have implemented/override didReceive of the UNNotificationServiceExtension in AppDelegate then, there you can simply check like this

let state = UIApplication.shared.applicationState

Neel Bhasin
  • 749
  • 1
  • 7
  • 22