iOS APNS 在后台模式下未收到
我试图在后台模式下接收通知。我不希望用户在收到通知中的警报后启动我的应用程序。但iOS似乎没有将通知发送到回调函数didReceiveRemoteNotification: 有任何输入吗?
为了在后台模式下接收推送,我需要执行一些特殊的操作吗?
仅供参考:我也尝试使用 voip 后台模式,但仍然没有任何结果!
基本上,我希望我的应用程序能够在不启动应用程序的情况下接收通知,并在应用程序在后台运行时执行某些操作。
I am trying to receive a notification when in background mode. I don't want the user to launch my app on receiving an alert in the notification. But it seems like iOS doesn't send the notification to the callback function didReceiveRemoteNotification:
Any inputs?
Is there something special I need to perform in order to receive a push in the background mode.
FYI : I tried using voip background mode also and still nothing!!!
Basically I want my app to receive a notification without launching my application and perform some action while application is running in background.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确实如此。如果您的应用程序位于后台,您将不会收到有关传入推送通知的通知,除非用户通过与通知警报交互来实际启动应用程序。
那是不可能的。
That's true. If your app is in the background, you will not get notified about an incoming push notification unless the user actually launches the app by interacting with the notification alert.
That's not possible.
可以获取远程通知并被唤醒。但了解当前实现及其如何受应用程序行为影响非常重要。在苹果的领导下,一切都可能发生变化。
在撰写本文时,您需要了解以下内容(大多数人显然都理解前两个):
application:didReceiveRemoteNotification
或更佳地application:didReceiveRemoteNotification:fetchCompletionHandler
application:didReceiveRemoteNotification:fetchCompletionHandler
并且您最好在 30 秒内调用该 fetchCompletionHandler,否则您的应用将终止。如果您没有使用 fetchCompletionHandler 实现该方法,那么您可能只能从系统接收徽章/警报如果您将其放入 APN 消息的内容中。否则,您将什么也看不到。现在,问题就在这里。当前的 iOS 分析您的应用程序,然后决定是否真正唤醒您的应用程序。如果您花费大量时间测试 APN,它最终会假设您的应用程序是坏公民,并且不会唤醒您的应用程序(除非您至少已接通电源)。它只会等到您的应用程序随后启动(您可以通过 APN 消息中的系统徽章/警报鼓励用户执行此操作),然后将该远程通知放入 UIApplicationLaunchOptionsRemoteNotificationKey 键下的 did/willFinishLaunchingWithOptions launchOptions 中
It is possible to get remote notifications and be woken up. But it is important to understand the current implementation and how it is affected by application behavior. All things are subject to change under Apple.
As of this writing, here is what you need to know (the first 2 most people obviously grok):
application:didReceiveRemoteNotification
or more preferablyapplication:didReceiveRemoteNotification:fetchCompletionHandler
application:didReceiveRemoteNotification:fetchCompletionHandler
and you better call that fetchCompletionHandler within 30 seconds or your app gets terminated. If you didn't implement the method with the fetchCompletionHandler, then you will probably only be able to receive a badge/alert from the System IF you put those in the content of the APN message. Otherwise, you will see nothing.Now, here is the catch. The current iOS profiles your application and THEN decides whether or not to actually wake up your app. If you spend a lot of time testing APN, it will eventually assume your app to be a bad citizen and it won't wake up your app (unless you are plugged into power at the very least). It will just wait until your app is subsequently launched (which you can encourage the user to do via the System badge/alert in your APN message), and then put that remote notification into the did/willFinishLaunchingWithOptions launchOptions under a key
UIApplicationLaunchOptionsRemoteNotificationKey