APNS 保存通知

APNS Save Notifications

我正在使用 APNS 处理 iOS 通知。我可以发送和接收通知。我想在 phone 上保存此通知。例如,我的应用程序通过 APNS 接收每日温度状态通知,此消息类似于 "temp: 25C 16.08.2016"。我想在收到通知时将此消息保存在 phone 用户默认值中。当用户想要查看过去的温度时,我想显示列表包括通知消息。喜欢列表;

2016 年 8 月 16 日 25C

15.08.2016 26C

14.08.2016 21C . . .

您可以在 AppDelegateapplication:didReceiveRemoteNotification: 方法中从 userInfo 中获取它。

appDelegate.m

  - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
        //Handle notification when the user click it while app is running in background or foreground.
        //Get Custom field data 1618
        NSLog(@"%@",userInfo );
        if(application.applicationState == UIApplicationStateInactive) {

            NSLog(@"Inactive - the user has tapped in the notification when app was closed or in background");
            //do some tasks


        }
        else if (application.applicationState == UIApplicationStateBackground) {

            NSLog(@"application Background - notification has arrived when app was in background");
    //do some tasks
        }
        else {
            NSLog(@"application Active - notication has arrived while app was opened");
           //do some tasks

        }


    }