简体   繁体   English

具有应用程序背景的iOS远程推送通知

[英]iOS remote push notification with app background

Looking on web and in many stackoverflow post i have seen that the only way to get remote push notification when the app is in background (and it is launched from icon and not from push message) is to call the server when the app is loaded and get the "last" messages. 在网络上和许多stackoverflow帖子中,我已经看到,当应用程序在后台运行时(从图标而不是从推送消息启动),获取远程推送通知的唯一方法是在加载应用程序时调用服务器并得到“最后”消息。

I've made this test with instant messaging app (i dont tell the name of the app, but i think you understand): 我已经使用即时通讯应用程序进行了此测试(我不告诉应用程序名称,但我认为您可以理解):

  • From another device i've sent one message to my device 我已从另一台设备向该设备发送了一条消息
  • When my device has received the notification i have wait for push notification pop-up to disappear. 当我的设备收到通知时,我已经在等待推送通知弹出窗口消失。
  • At this point i have take device offline (no internet connection) 此时,我已使设备离线(没有互联网连接)
  • I have then open the application and in the list the message was correctly added 然后打开应用程序,并在列表中正确添加了消息

So, if i'm in foreground, i can handle the notification on method didReceiveRemoteNotification. 因此,如果我处于前台,则可以处理关于didReceiveRemoteNotification方法的通知。

If the app is in background i can handle the nofification in didFinishLaunchingWithOptions (if i launch it with push notification pop-up). 如果应用程序在后台运行,我可以在didFinishLaunchingWithOptions中处理命名(如果我使用推送通知弹出窗口启动它)。

How it's possible to handle the notification when the application is in background and it is launched from icon and not from the push pop-Up? 当应用程序处于后台并且从图标而不是从推送弹出窗口启动时,如何处理通知?

Thanks 谢谢

  • (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { (void)应用程序:(UIApplication *)应用程序didReceiveRemoteNotification:(NSDictionary *)userInfo {

    UIApplicationState state = [application applicationState]; UIApplicationState状态= [应用程序applicationState];

    if (state == UIApplicationStateActive) { // write code here for handle push notification when app is in foreground } else { // write code here for handle push notification when app is in background } } if(state == UIApplicationStateActive){//在应用程序处于前台状态时在此处编写处理推送通知的代码} else {//在应用程序处于后台状态时用于编写处理推送通知的代码}}

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

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