How to fetch and display the message in push notification from dynamic notification service
push: {
aps = {
alert = "My First Notification";
sound = default;
Msg = {
myData = (
{
Msg = "Awesome";
Id = 123;
Date = "Jan 18 2018";
}
);
};
};
}
As i want to display alert = "My First Notification" and Msg = "Awesome" when push notification arrives. I have no idea how to fetch and display. Please help me to solve this issue. TIA
I have tried below code
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[application registerForRemoteNotifications];
return YES;
}
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSLog(@"My token is: %@", deviceToken);
NSString *deviceTokenStr = [[[[deviceToken description]
stringByReplacingOccurrencesOfString: @"<" withString: @""]
stringByReplacingOccurrencesOfString: @">" withString: @""]
stringByReplacingOccurrencesOfString: @" " withString: @""];
NSLog(@"Device Token: %@", deviceTokenStr);
}
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
NSLog(@"Failed to get token, error: %@", error);
}
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{
NSLog(@"Received notification: %@", userInfo);
NSUserDefaults * loginDefaults = [NSUserDefaults standardUserDefaults];
UIApplicationState state = [[UIApplication sharedApplication] applicationState];
if (UIApplicationStateActive == state )
{
return;
}
}
I Want to display it in push notification only.
As far as I understand from your comments you want your push to display title
My First Notificationand message (or body)Awesomeon the notification screen. To do that you don't need to write the code in the app. It's the structure of the payload that does the magic.Currently you're sending payload as
Which will not display
Awesomemessage on the notification screen as per apple docsTo display
Awesomemessage on the notification screen you need to specifybodykey. Create a payload like below and send this push, you'll see the title and body on the notification screen. Also go through the above docs for more informationsAt the end I would like to add that in android we need to write the code in the app to display the push notification whereas in ios we don't have to write the code or to be more precise our app doesn't control how the push will be displayed. It's all upto the server that is sending the data to APNS with appropriate keys