i have a working App witch sends without any problems my Push Notifications.
After clicking the "View" Button of the Push - the App is open, but a blank screen is seen, without any content.
How will i get it to work, that after clicking the View Button i will see "Content" in the App?
My idea is (for example):
I receive a Push Notification with the following Content: Today you get a Discount of 30% in our Shop
After clicking View i will get into the App and can read the full Message with all content.
I mean working like a Blog. The Push Notification is the Pre-Article and the "View" Button the "Read More" Tag. And in my App i have several Articles witch i can read.
Just like here: http://www.myfitapp.de/fitnessstudio-app/push-nachrichten/
Is it possible? And how?
Yes, of course this is possible. But you can't send the a lot of content with the push notification.v The push notification can be a maximum of 256 bytes in total.
What you can do is add some data to the userInfo of the notification, link an ID. Then after te user opens you app fetch the content from a server by parsing out the ID in the notification.
If your app isn't running when the user clicks on the notification
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSDictionary *remoteNotif = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
if (remoteNotif) {
///Handle the notification
}
/* Your regular init */
return YES;
}
If your app is running this method is called:
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
///Handle the notification
}
In the NSDictionary
you can get the notification msg and any other data you have added to the notification.
--
The Userinfo part of the push notification it is just JSON, The Notification Payload.
{
"aps" : {
"alert" : "You got your emails.",
"badge" : 9,
"sound" : "bingbong.aiff"
},
"acme1" : "bar",
"acme2" : 42
}
This example from Apple, the aps
part of the JSON tells the app to show 9 in badge icon and "You got your emails." as the message text. On receiving this notification the system looks in the app bundle for the bingbong.aiff
sound and if found plays it.
The other keys, amce1
and amce2
are send with the notification and you can acces the from the dictionary that is the push notification.
You can redirect your application to any particular view, when your application will receive notification.Delegate method for this is:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
You can also pass extra parameters in userInfo dictionary from server side as per your requirement, for example:blog_id in your case and pass that id to your view,which you want to load on "View" or "Read More" button.