I've searched in all questions here but no solution worked.
I scheduled localNotifications with a userInfo option. When app is in foreground, the notification arrived and a can handle perfectly with this function that system calls by itself.
For local notifications
func application(_ application: UIApplication, didReceive notification: UILocalNotification) { if application.applicationState == .active { return } //My implementation }
For remote notifications
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) { if application.applicationState == .active { return } //My implementation }
But the problem is, when app is closed, this functions are not called and I can't handle the data that I need.
I've tried get userInfo in that function in appDelegate:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
if let localUserInfo = launchOptions?[UIApplicationLaunchOptionsKey.localNotification] as? [AnyHashable: Any] {
// My implementation
} else if let remoteUserInfo = launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] as? [AnyHashable: Any] {
// My implementation
}
return true
}
But.. Didn't work...
Someone could help me please?
Thanks in advance.