How to manage notification when users click on the icon

I have a question to ask about notifications. In a few hours, he is now arriving to learn how to implement push notifications on the iPhone!

How do I manage users who click on the icon or click preview in alert mode? What happens when users click there?

I tried to send me a notification and a number on the application icon with a step in the bridgehead. How can I click there, can I show uiview to manage the received notification and show the message read and unread?

Does he have a textbook? I want to keep all posts inside a uitableview.

+6
source share
1 answer

You want to read Local and Remote Notification Handling

Mainly in the deletion of the application you want to implement:

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

and

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

And handle startOptions / userInfo for notification data.

How do I usually process data:

 - (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSDictionary* userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; if (userInfo) { [self processRemoteNotification:userInfo]; } [window addSubview:viewController.view]; [window makeKeyAndVisible]; return YES; } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { [self processRemoteNotification:userInfo]; } 

The format for user information is documented in the "Payload" section .

eg. the β€œaps” key will give you another NSDictionary, and then searching for the β€œalert” key will give you the warning message that was displayed. In addition, there will also be any user data that you send in the JSON payload.

 NSDictionary *apsInfo = [userInfo objectForKey:@"aps"]; NSString *alertMsg = @""; NSString *badge = @""; NSString *sound = @""; NSString *custom = @""; if( [apsInfo objectForKey:@"alert"] != NULL) { alertMsg = [apsInfo objectForKey:@"alert"]; } if( [apsInfo objectForKey:@"badge"] != NULL) { badge = [apsInfo objectForKey:@"badge"]; } if( [apsInfo objectForKey:@"sound"] != NULL) { sound = [apsInfo objectForKey:@"sound"]; } if( [userInfo objectForKey:@"Custom"] != NULL) { custom = [userInfo objectForKey:@"Custom"]; } 
+34
source

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


All Articles