iOS Local Notification - Callback when in Background

前端 未结 1 627
难免孤独
难免孤独 2020-12-30 10:23

Context: My iOS App uses local notifications I schedule local notifications and then I get a call back via didRecieveLocalNotifications when the notifications fire.

相关标签:
1条回答
  • 2020-12-30 10:58

    You are describing application:didReceiveLocalNotification:. This is deprecated in iOS 10. You should be updating to the UserNotification framework.

    Now then.

    If you app is frontmost, the user gets no alert. Instead, you get application:didReceiveLocalNotification:.

    If your app is not frontmost, the user gets an alert. Therefore, you do not get application:didReceiveLocalNotification: because the notification fired. But you do get it if the user received the notification and summoned your app by tapping the notification alert. If the user does that, you will get application:didReceiveLocalNotification: even in the background.

    If your app was terminated in the background, however, you will get application:didFinishLaunchingWithOptions: (and you can check the options to learn that you're being launched because of the notification).

    If your app was in the background or not running, and the user does not tap the notification and summon your app, you will get nothing at all and will have no way to know that the notification fired. This is because notifications are not for your benefit but are a way of sending a message to the user. (It sounds, from your question, as if you may be misusing local notifications as a way of sending a message to yourself. That is not what they are for.)

    0 讨论(0)
提交回复
热议问题