0

My app receives push notifications normally but none of the UIApplicationDelegate methods are called (looking at application(_:didReceiveRemoteNotification:) specifically). This only happens in the first session of the app (the session where user approves push notifications). If I kill the app and run it again, I still receive the notifications but then the delegate methods are called correctly.

How is this possible, has anyone face this problem before? It's a pretty basic implementation of push notifications.

Dixit Akabari
  • 2,419
  • 13
  • 26
zbx
  • 279
  • 1
  • 3
  • 11
  • not sure, but I'm guessing your tokens weren't registered early enough, and you closing the app or something else, triggers it to register the tokens... – mfaani Oct 12 '17 at 14:26
  • just to got you right - your code isn't called anymore after terminating your app? for example - application(_:didReceiveRemoteNotification:) -> if that's the case, please have a look at the following stackoverflow topic: https://stackoverflow.com/questions/46330053/ios11-swift-silent-push-background-fetch-didreceiveremotenotification-is-not/46392357#46392357 – AlexWoe89 Oct 12 '17 at 14:39

1 Answers1

0

To receive push notifications you have to register your token beforehand. If you are only receiving notifications after the second run I assume that you are sending your token to your service when you close the app or something.

You can use this to check the exact moment in which you are obtaining your notifications token:

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
    print("DEVICE TOKEN = \(deviceToken)")
}

Try to get the token and send a push notification manually to that token from your service after you obtain it.

jvrmed
  • 834
  • 6
  • 12