简体   繁体   English

在iOS上将推送通知作为后台应用获取

[英]Get push notification as background app on iOS

I am making a certain application. 我正在申请。

Which has these functions. 具有这些功能。

1 This application has push notification. 1此应用程序具有推送通知。

2 This application can stock the push notification log when it is active. 2此应用程序可以在活动时存储推送通知日志。

3 This application can stock the push notification log when it is not active. 3此应用程序可以在不活动时存储推送通知日志。

1,2 is OK for me. 1,2对我来说还可以。 1 is normal, 2 is accomplished by push notification callback. 1是正常的,2是通过推送通知回调完成的。

However 3...? 但是3 ...?

I guess on Android background job works and get the notification. 我猜想在Android后台工作正常并收到通知。

but is it impossible on iOS? 但是在iOS上不可能吗?

In addition to the previous answer: about didFinishLaunchingWithOptions . 除了先前的答案:关于didFinishLaunchingWithOptions This only works when the program is launched by clicking on the notification/push message window. 这仅在通过单击通知/推送消息窗口启动程序时有效。 But if you run the app directly, by clicking on the app icon, even when the notification/push message arrives, you will not receive any data in launchOptions about push message. 但是,如果直接通过单击应用程序图标运行该应用程序,即使通知/推送消息到达,您也不会在launchOptions收到有关推送消息的任何数据。 So about the paragraph 3: you can know it only if user tap on push message window/bar. 关于第3段:只有在用户点击推送消息窗口/栏时,您才能知道它。

When the application is not active, you can handle the push notification using didFinishLaunchingWithOptions delegate method: 当应用程序处于非活动状态时,可以使用didFinishLaunchingWithOptions委托方法处理推送通知:

   UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
    if (localNotif) {
NSString *json = [localNotif valueForKey:@"data"];
// Parse your string to dictionary
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM