Can I get notification information (apn)

Can I get a list of push notifications (APNS notifications) for my application when the application has switched from background to foreground mode? In foreground mode, I can receive push notification information in a callback

- (void) application: (UIApplication *) application didReceiveRemoteNotification: (NSDictionary *) userInfo

Another case:

My application receives a push notification when the application is in the background . After that, I click the application icon , and I want to receive information about the notification received. How can I get this information?

If I click directly on the notification (and not on the application icon) in the background, then the didReceiveRemoteNotification callback is a call .

+4
source share
2 answers

Can I get a list of push notifications (APNS notifications) for my application when the application has switched from background to foreground mode?

No. There is no list. You can receive only one notification at a time. When iPhone users are disconnected and you send 5 notifications, the user will receive only the last one you send.

If the user starts your application using the open action in the notification, you will receive it at startup using:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 

Another thing

My application receives a push notification when the application is in the background. After that, I click the application icon and I want to receive information about the notification received. How can I get this information?

You can not. When the user closes the notification and opens the application later, he has already left and there is no access to it.

When sending push notifications, you probably have access to the server via the Internet, where you register the user's devices.

The usual way to deal with this is to save notifications on this server and request it when the application starts ... so use the notification to notify the user about the launch of your application, and then check your server when the application starts for anything you want.

+3
source

As soon as your application reaches priority and is actively running, alert notifications such as sound, warning will not be displayed, or you will not be notified.

But you will get a response in the UIApplication delegate, which you can use.

Api is

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken ;

And if your application runs in the background, a notification will appear, and only when you click the "View" button, you will receive a response in the UIApplication delegate.

If you click the "Close" button, you will not receive a response in the application.

0
source

Source: https://habr.com/ru/post/1388000/


All Articles