Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to manage notification when users click on badge

I have a question to ask about notifications. After some hours to learn how to implement push notifications on iPhone, it now arrives!

How do I manage users that click on badge or click view on alert? What happen when users click there?

I tried to send me some notification and the number on the icon of application in springboard increments. In which way clicking there it's possible to show a uiview to manage the notification arrived and show the message read and unread?

Is there a tutorial for it? I want to save all the messages inside a uitableview.

like image 499
Jayyrus Avatar asked Dec 31 '11 00:12

Jayyrus


People also ask

How do I turn on notifications badges?

To Disable App Icon Badges Entirely If your Samsung Galaxy smartphone runs Android 11 or 12, open the Settings app and head into the "Notifications" menu. Then, tap "Advanced settings" and toggle off the "App icon badges" switch.

What does badges do in notification?

Starting with 8.0 (API level 26), notification badges (also known as notification dots) appear on a launcher icon when the associated app has an active notification. Users can long-press on the app icon to reveal the notifications (alongside any app shortcuts), as shown in figure 1.

What is a badge notification on iPhone?

What are notification badges? They're the red dot, usually with a number inside, showing how many notifications you have received in any given app. Badges can appear on the app icons of your home screen, in the App Library, or on both or neither.


1 Answers

You want to read Handling Local and Remote Notifications

Basically in your application delegate, you want to implement:

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

and

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

And process the launchOptions / userInfo for the notification data.

How I normally process the data is:

- (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 userInfo is documented the The Notification Payload section.

e.g. the "aps" key will give you another NSDictionary, then looking up the "alert" key will give you the alert message that was displayed. Also, any custom data you send in the JSON payload will be in there as well.

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"];
}
like image 195
Shane Powell Avatar answered Nov 15 '22 06:11

Shane Powell