Search code examples
iphoneapple-push-notificationsurbanairship.com

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


Solution

  • 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.