0

I am currently working on remote push notifications, I need to know if there is a way to supply additional information in the notification that will be available to the app but will not be shown to the user (in the alert message).

I tried to search on Google before posting but i didn't find any solution for my problem.

Wain
  • 118,658
  • 15
  • 128
  • 151
Iphone User
  • 1,930
  • 2
  • 17
  • 26
  • You mean you do not want to show text in Notification area? – Retro Dec 30 '13 at 09:29
  • @Retro , i need to change the native notification popup text before displaying on the screen..is it possible? – Iphone User Dec 30 '13 at 09:52
  • You mean you want information in the push which is available to the app but not displayed to the user? – Wain Dec 30 '13 at 16:09
  • yes .. thats exactly what i need ..i still wasnt able to test Retro answer since APNS pusher was not able to handle the format ..so still waiting my server side to implement it @Wain – Iphone User Dec 31 '13 at 11:12
  • Duplicate of http://stackoverflow.com/questions/11236630/can-apple-push-notifications-send-more-parameters-than-alert-and-sound – Wain Dec 31 '13 at 12:50

4 Answers4

4

There is the trick which i used in mu app but need to do at payload end

the default payload is look like

{
    "aps": {
         "badge": 10,
         "alert": "Hello world!",
         "sound": "cat.caf"
    }
}

and notification log show the alert message text so you can change the alert message like

{
    "aps": {
         "badge": 10,
         "alert": "You got the new message",
         "sound": "cat.caf"
    }
   "message" : "The message you want to use later to show in application"
}

and this key comes with payload to work handy, hope this help you

Retro
  • 3,985
  • 2
  • 17
  • 41
0

When you receive a remote notification, this method is being called in delegate. OK? Now you can handle on the bases of each state by reading userInfo dictionary. Whether show same text or different one in an alert of not. You can customize as per your needs.

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    if ( application.applicationState == UIApplicationStateActive )
        // app was already in the foreground
    else
        // app was just brought from background to foreground
    ...
}
Shahab Qureshi
  • 952
  • 1
  • 7
  • 19
  • this is not what i need, i need to change the text of the native notification popup when a push is received before displaying it to user(the one that appears in home screen)..maybe it is not possible because the application will be closed, but i am asking hoping that there is a way to do it.. – Iphone User Dec 30 '13 at 09:59
0

You have two scenario here.

If application is running (Foreground): Then -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo gets triggered in app delegate class. You can perform whatever action you want within this method. (displaying a alert dialog etc.)

If application is not running (Background): Well in that case you can not do much, text will be displayed as it is.(defined in notification script of server part)

Gyanendra Singh
  • 1,483
  • 12
  • 15
  • Hmmm, thank you:) Seems that i need to find some other way to receive the data from push. because the native notification popup will not appear unless the application is closed or in background. Thanks anyway for your help here:) – Iphone User Dec 30 '13 at 10:03
  • that's why we are here to help each other. Thanks :) hope you will find what u r looking for. – Gyanendra Singh Dec 30 '13 at 10:05
  • You can define different situation like (consider all scenario) "Image added", "Liked", "Commented" etc in your backend and populate the text in the payload accordingly. – Gyanendra Singh Dec 30 '13 at 10:16
0

Use this code in your Appdelegate class

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { UIApplicationState state = [application applicationState];

if (state == UIApplicationStateActive)
{
    NSLog(@"User Info : %@", [userInfo description]);

    NSLog(@"User Info Alert Message : %@", [[userInfo objectForKey:@"aps"] objectForKey:@"alert"]);

    NSString *messageString = [NSString stringWithFormat:@"%@", [[userInfo objectForKey:@"aps"] objectForKey:@"alert"]];

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Red-Vs-Blue" message:messageString delegate:self cancelButtonTitle:@"Done" otherButtonTitles: @"Cancel", nil] ;
  //here you can change alert title and message according your choice
    [alert show];
}
Gajendra Rawat
  • 3,673
  • 2
  • 19
  • 36