scb998
scb998

Reputation: 909

display Push notification text in a UIAlert View

I am using Parse to deliver push notifications to my app. What i would like is, when the user swipes the notification from the lock screen, or taps it from the home screen, that it opens up the app and displays the text of the Push notification in a UIAlert View.

I imagine that it would slot into the didfinishlaunchingwithoptions method of the app delegate, but i really have not got a clue on how to extract the text of the alert.

Any advice would be greatly appreciated.

So below is my code to display the alert - which is working, but it displays the full JSON message - and when i try to use the objectForKey:@"alert statement to try and extract just the "alert" part of the push notification, nothing is displayed in the message section of the alert.

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    [PFPush handlePush:userInfo];
    pushText = [userInfo objectForKey:@"alert"];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"News", "")
                                                    message:pushText
                                                   delegate:nil
                                          cancelButtonTitle:@"Ok"
                                          otherButtonTitles: nil];
    [alert show];




}

Upvotes: 0

Views: 110

Answers (1)

glyvox
glyvox

Reputation: 58069

You can put this code to the didFinishLaunchingWithOptions section and then display the pushText variable in a UIAlertView.

NSDictionary *notifKey = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];

if (notifKey)
{
    pushText = [notifKey objectForKey:@"alert"];
}

Upvotes: 1

Related Questions