简体   繁体   English

iOS:通话在后台运行时确实收到了远程通知委托

[英]IOS:call did receive remote notification delegate when app is in background

My app contains push notification functionality and i have done the part of coding to receive push notification in my application.When my app enters to background i am receiving push notifications and when i click push notification button app come to foreground and calling did receive remote notification delegate method.I need to call the same delegate method when my app receives push notification in background but without opening the app by clicking push notification button on the top of the screen.I have written code as below. 我的应用程序包含推送通知功能,我已经完成了部分编码以在我的应用程序中接收推送通知。当我的应用程序进入后台时,我正在接收推送通知,并且当我单击推送通知按钮时,应用程序进入前台并且调用确实收到了远程通知委托方法。当我的应用程序在后台收到推送通知但没有通过单击屏幕顶部的推送通知按钮打开应用程序时,我需要调用相同的委托方法。我编写了以下代码。

   if ([application respondsToSelector:@selector(registerUserNotificationSettings:)])
 {
    UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
                                                    UIUserNotificationTypeBadge |
                                                    UIUserNotificationTypeSound);

   UIUserNotificationSettings *settings = [UIUserNotificationSettings 
  settingsForTypes:userNotificationTypes

   categories:nil];
    [application registerUserNotificationSettings:settings];
    [application registerForRemoteNotifications];
}
else
{
    // Register for Push Notifications, if running iOS version < 8
    [application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                                     UIRemoteNotificationTypeAlert |
                                                     UIRemoteNotificationTypeSound)];
}

 if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
    [application registerUserNotificationSettings:[UIUserNotificationSettings  



     settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge
   |UIUserNotificati
 onTypeSound categories:nil]];
  }

My final intension is to call did receive remote notification when app is in background also. 我的最后意图是在应用程序也处于后台时致电确实收到了远程通知。

The didReceiveRemoteNotification delegate won't be invoked when the app is closed or in background.When you tap on the notification,it launches the app and the method will be invoked.You can do required action at this moment like decrementing the icon badge. 当应用关闭或在后台运行时, didReceiveRemoteNotification委托将不会被调用。当您点击通知时,它将启动应用并调用该方法。此时您可以执行所需的操作,例如减少图标标志。 This is the working flow of push notification in iOS .One more thing is when the app is closed and you are taping on notification,didReceiveRemoteNotification won't be invoked. 这是iOS中的推送通知的工作流程 。还有一件事是,当应用程序关闭并且您点击通知时,didReceiveRemoteNotification将不会被调用。 ApplicationDidFinishLaunching will be called and you can identify there using launchoption dictionary whether its launched from notification ApplicationDidFinishLaunching将被调用,您可以使用launchoption字典在其中识别是否从通知中启动

If App receives Notification in background & user will open app without tapping on notification than that notification will not be received at all. 如果应用程序在后台收到通知,并且用户将打开应用程序而不点击通知,则该通知将根本不会收到。

To achieve this you need to try different thing. 为此,您需要尝试其他事情。

Here is an idea that might help you: 这是一个可以帮助您的想法:

When Notification pushed from the server & received successfully in App you can send message through Api that it received. 当通知从服务器推送并成功在App中收到时,您可以通过Api发送收到的消息。

Now if in above case where notification not received in the app server will not get the successful receive message. 现在,在上述情况下,如果在应用服务器中未收到通知,则不会收到成功的接收消息。 So in this case it can be saved at server in pending notifications table. 因此,在这种情况下,可以将其保存在服务器的未决通知表中。

Now once you open up the device 1 api will check if any pending notifications on the server & if found than will get that in response & after that it will be removed from the server. 现在,一旦打开设备1,api将检查服务器上是否有任何待处理的通知,如果发现,则将得到响应,之后将其从服务器中删除。

Note: Its an idea that is tried earlier & working. 注意:这是一个较早尝试并起作用的想法。 You can improve it as per your requirement. 您可以根据需要进行改进。

Hope it will work for you. 希望它对您有用。

暂无
暂无

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

相关问题 当APP在iOS中收到外部通知时检测背景模式 - Detect BACKGROUND mode when APP receive external notification in iOS (iOS MPMusicPlayerNotification)如何在应用程序处于后台时接收通知 - (iOS MPMusicPlayerNotification) how to receive notification when app is in the background 当后台iOS 11中的应用程序运行时,UNNotification本地通知用户点击不会触发委托 - UNNotification local notification user tap does not trigger delegate when app in background iOS 11 IOS 9远程通知中的滑动按钮-在后台运行应用程序时可用,而在内存不足时可以使用 - Swipe Buttons in IOS 9 Remote Notification - Work when app in background not when app out of memory 应用程序在后台时不调用远程通知 - Remote notification is not called when app is in background 应用程序未运行时未收到远程通知 - App doesn't receive remote notification when it is not running 如何在应用程序处于后台时处理 iOS 远程通知 - How to handle iOS remote notification while app is in background 当app在后台时,如何对接收推送通知执行操作? - how to perform action on receive push notification when app is in background? iOS 10:如何在应用程序处于后台时显示传入的VOIP呼叫通知? - iOS 10: How to show incoming VOIP call notification when app is in background? 当应用被杀死时,iOS不会收到推送通知 - iOS doesn't receive Push notification when the app is being killed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM