iOS push notification message - action after clicking VIEW button
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.
emitremmus
Updated on June 04, 2022Comments
-
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 almost 12 yearsOk, 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 almost 12 yearsOk, 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 almost 12 yearsHave 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 almost 12 yearsJust take a look at the
NSDictionary
you get (who is sending this push message? not you?) -
emitremmus almost 12 yearsHello, 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 almost 12 yearsI 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 almost 12 yearsWhich "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 almost 12 yearsI 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 almost 12 yearsI 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 almost 12 yearsyes, 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.