Pugalmuni
Pugalmuni

Reputation: 9390

Apple Push Notification Service using Urban Airship in iPhone

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

Upvotes: 1

Views: 1846

Answers (2)

chilitechno.com
chilitechno.com

Reputation: 1575

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];
     }    
}

Upvotes: 1

robotadam
robotadam

Reputation: 1153

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.

Upvotes: 4

Related Questions