iOS push notification message - action after clicking VIEW button

13,565

Solution 1

Just implement the following code and you are good to go:

// will be called if the app was not active
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self applicationDidFinishLaunching:application];

    if (launchOptions != nil)
    {
        NSDictionary* dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
        if (dictionary != nil)
        {
            // get the necessary information out of the dictionary 
            // (the data you sent with your push message)
            // and load your data
        }
    }
    return YES;
}

// will be called when in foreground
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {    
    // get the necessary information out of the dictionary 
    // (the data you sent with your push message)
    // and load your data
  }

You can find a well-known tutorial on APNS here: http://www.raywenderlich.com/3525/apple-push-notification-services-tutorial-part-2

Solution 2

If your app was not in the background when the user taps the view button, application:didFinishLaunchingWithOptions: is called. The dictionary in the second argument of the method contains information about the cause of the launch (direct, from push or local notification, etc.) and about the contents of the notification.

If your app was already in the background, application:didReceiveRemoteNotification: is called when it wakes up. Again, the second argument is a dictionary that contains the contents of the notification.

Share:
13,565
emitremmus
Author by

emitremmus

Updated on June 04, 2022

Comments

  • emitremmus
    emitremmus almost 2 years

    i have some problems with the Push Notifications. I can sent them well to my registered Devices. All works fine.

    My Questions is: After clicking the VIEW button, the App is launching. At the moment without any content.

    How can i add content here? This content should depend on the Push Notification i sent out.

    For example: My Push Notification is about NEWS Number 1 - then after clicking VIEW i should get more informations about NEWS Number 1

    and so on...

    Also it should be possible to read all previous received NEWS in the App in a list, when getting back from NEWS Number 1.

    You understand, what i mean?

    I dont have any real idea...Would be nice if you can show me code regarding to an example.

    Thanks.

  • emitremmus
    emitremmus almost 12 years
    Ok, thank you for your post. But for me it is important to know more about this in your code: // get the necessary information out of the dictionary // (the data you sent with your push message) // and load your data Can you give me an example. I want to use it with a Wordpress Post. So the Post ID i want to use. But i dont know how to implement it into the App
  • emitremmus
    emitremmus almost 12 years
    Ok, thank you for your post. But for me it is important to know more about this in your code: // get the necessary information out of the dictionary // (the data you sent with your push message) // and load your data Can you give me an example. I want to use it with a Wordpress Post. So the Post ID i want to use. But i dont know how to implement it into the App
  • Ole Begemann
    Ole Begemann almost 12 years
    Have you even tried to look at the dictionary yourself? It's really straightforward. And I can't give you any specific info since I know nothing about the contents of the notification or the structure of your app.
  • tilo
    tilo almost 12 years
    Just take a look at the NSDictionary you get (who is sending this push message? not you?)
  • emitremmus
    emitremmus almost 12 years
    Hello, i had a look at the NSDictionary. The following i want to do: Sent i Push Notification with some Info. At the same Page i also fill out another Message (with all inforamtions, some Images, etc.). After receiving the Push Notification on my iPhone i click on the VIEW Button and can read the Message with all Informations. You now what i mean? On a website (html) i make at the same time 2 messages. One message is the real Push, the other is the message, witch i read after after clicking the VIEW button.
  • emitremmus
    emitremmus almost 12 years
    I am sending the Push. Hello, i had a look at the NSDictionary. The following i want to do: Sent i Push Notification with some Info. At the same Page i also fill out another Message (with all inforamtions, some Images, etc.). After receiving the Push Notification on my iPhone i click on the VIEW Button and can read the Message with all Informations. You now what i mean? On a website (html) i make at the same time 2 messages. One message is the real Push, the other is the message, witch i read after after clicking the VIEW button.
  • tilo
    tilo almost 12 years
    Which "Page" are you talking about? I have no idea what you really want to do. If you want to load additional content after receiving the push notification: just grab it from your server with a specific ID.
  • emitremmus
    emitremmus almost 12 years
    I have made a Interface, a html Site, where i sent my Push Notifications. Just look here. www.webdesign-rothe.de/iphoneapp/. But the big problem is, i receive the Message and after clicking VIEW button the App opens with blank content. I just want to sent out the PUSH and after clicking i want to read the "real" longer Message/News. So my question is, how can i do? I read about the NSDisctionary but actually i have no really glue how to implement it. Also the with every new message, the ID of message/news is different. How to implement it in the App?
  • tilo
    tilo almost 12 years
    I posted the answer to this in my original answer. Just implement the code above, get the message/news ID and load related content from your server.
  • emitremmus
    emitremmus almost 12 years
    yes, and thats why i asked again. because i not really know, witch "code" i have to implement in the NSDictionary. Thats why i asked perhabs for a example, maybe for a WordPress Blog Entry or so. This would help me alot, in understand this part of development.