Pergunta

When the push notification arrived, user click the app directly , the push notification remain in notification center. how can i get the message from notification center ? i want to get it and save it locally so users can view them later.

I can save the push notification if i click the alert from the notification center when the push notification arrived. or i can save the push notification when the app is running.

in AppDelegate.m

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    [PFPush handlePush:userInfo];

    //save the alert
    [FunctionNSObject savePushNotification:userInfo];
}

in MyTableViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];


    //load push notification from file
    sortedMessages = [FunctionNSObject loadPushNotification];
}
Foi útil?

Solução 2

Your reasoning is flawed--push notifications are meant to be transient, they can be tied to an event (such as an email being received) but they are not the event itself. In the email example, all the push is supposed to do is to tell the email app that there is a new email and maybe contain some content that will give a hint to the email content, but the actual content of the email is not the job of the notification to deliver--that needs to be fetched separately. APNS is a system for sending events to remote clients, it is not the content system itself.

The way systems like Facebook or whatsapp deal with this is that they have their own message system and they use APNS to inform the applications that there is a new message in the inbox, then the app will fetch the content for the user by pulling it from the server.

If you want to build a system like this then you can still use APNS but APNS should inform your client that there is new content available to fetch and you will need a server that manages the cloud inbox.

Outras dicas

you can add below code in didFinishLaunchingWithOptions

if ([[launchOptions allKeys] containsObject:UIApplicationLaunchOptionsRemoteNotificationKey]) {

        id userInfo=[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

    }

this method call when application is close and click on notification and you only get this notification info

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