views:

102

answers:

2

Hi friends,

I have implemented Apple Push Notification service using Urban Airship and successfully received the notification in my application. If i receive the notification the alert view comes, If i click the view button in alert view, it goes to start the application. Generally it happens in APNS. But my client wants, If any updates happened in the RSS feed and alert view comes, If we click the view in alert view, it should go to the particular feed in the application, doesn't start the application. SO is it possible to do that?. Is any possible to write the events for the particular alert view buttons in my application.

Here my sample code is,

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

       [[UIApplication sharedApplication] registerForRemoteNotificationTypes:   UIRemoteNotificationTypeBadge                                                           | UIRemoteNotificationTypeSound                                                                          | UIRemoteNotificationTypeAlert];

        [window addSubview:viewcontrollers.view];

        [window makeKeyAndVisible];

        NSLog(@"remote notification2: %@",[launchOptions description]);

      return YES;

     }

In this method didFinishLaunchingWithOptions, i cant get the dictionary values and it always get the Null Value. Is any possible to get the dictionary value in this method(Notification comes).

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

            NSString *message = [userInfo descriptionWithLocale:nil indent: 1];

            NSLog(@"The message string is %@",message);

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Remote Notification" message: message delegate: nil cancelButtonTitle: @"ok" otherButtonTitles: nil];
            [alert show];
            [alert release];
      }

In this method, i could get the dictionary value. But this method calls only,if any update happens while running in the application.

Please guide me!

Thanks

+1  A: 

It is indeed possible to do that. In your application:didReceiveRemoteNotification method you'll be passed an NSDictionary with all of the push notification's data. What you'll want to do is send some ID or URL in the payload to Urban Airship. Something like:

{
    "aps": {
        "alert": "New RSS entry"
    },
    "entry_id": "XYZ123"
}

And then you can write code to go and fetch the proper feed entry in your application.

robotadam
+1, @robotadam, Thanks for the reply. See my updated question and please mentioned What i have done wrong. Thanks.
Pugal Devan
I'm not sure what your question is now -- you have the data from the push notification, yes? The rest seems like it would be a hook into the rest of your code.
robotadam
@robotadam - I think he's saying that application:didReceiveRemoteNotification is only getting called when it's the app is in the foreground when a notification comes in.
chilitechno.com
A: 

When the application isn't running or has been terminated by the system and the app is launched via the notification:

In this case you have to get the notification dictionary (which is itself a value of the launchOptions):

http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/doc/uid/TP40006786-CH3-SW18

I imagine the code would be something like this:

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

     NSDictionary *remoteNotification = (NSDictionary *) [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
     if (remoteNotification != nil) {
           NSString *message = [remoteNotification descriptionWithLocale:nil indent: 1];
     }    
}
chilitechno.com