Pergunta

I am using Parse.com to send out the push notification message, it is working great, but i want to save those messages into an Array and display for the users in my APP. I have created an NSObject class and declared an array of data to be used throughout the application by other classes. However, when I call the method from AppDelegate class, it returns the address of the notification messages. Am I going right about it?

If someone can help I will be eternally grateful. Thanks in advance.

Foi útil?

Solução

Its possible but only in case if user will open application from received push. Otherwise application will not get data from Push notification payload.

Update:

The answer posted by @Vineesh is correct. To grab the messages out of the push notification that you receive, you need to implement the didReceiveRemoteNotification method as below

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    NSLog(@"userInfo  %@",userInfo);


   // you can get the required message as below

     NSString *msg = [[[userInfo valueForKey:@"aps"] valueForKey:@"alert"] valueForKey:@"body"];

}

Outras dicas

Add these lines of code in didFinishLaunchingWithOptions

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[UIApplication sharedApplication]registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound|UIRemoteNotificationTypeAlert)];

}

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    NSLog(@"userInfo  %@",userInfo);
}

In the " userInfo" you can get pushnotification message.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top