简体   繁体   中英

Swift: doesn't call didReceiveRemoteNotification()

Here's my sample app

在左侧,您可以看到应用程序委托,在右侧,是我的视图控制器

I've had some trouble with this in another app and I'm trying to figure out what I'm doing wrong; It works like this:

  1. I push a button that schedules the notification
  2. I quit the app and close it
  3. I wait for the notification to arrive
  4. I restart the app through Xcode

The thing is: even though the didReceiveRemoteNotification()-function should be called, I still get false value when starting the app which shows me, that for any reason this method does not get called. Why? Can you help me?

Method didReceiveRemoteNotification() is not supposed to be called for local notifications... It's only for remote notifications (Push Notifications).

Use UNUserNotificationCenterDelegate delegate method

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)

See details here https://stackoverflow.com/a/44142742/1825618

Get delivered notifications (Only the ones Currently being displayed in notification center)

UNUserNotificationCenter.current().getDeliveredNotifications {
    (notifications) in
    // your code
}

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