Domanda

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.

È stato utile?

Soluzione

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"];

}

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top