当收到推送通知时,应用程序可以根据用户词典决定显示警报吗?
当您收到推送通知时,是否可以让您的应用程序决定是否显示 AlertView 来指示您收到了推送通知?
或者操作系统只是自动控制这一点而不让您对此有任何控制权?
我希望收到一些发送给我的应用程序的通知,然后让我的应用程序根据 didReceiveRemoteNotification,是否显示警报或某些用户可见的通知?这有可能以任何方式吗?
Is it possible when you receive a push notification to somehow have your application decide whether or not to show the AlertView indicating you received a push notification?
Or does the OS just automatically control this and not let you have any control in this?
I would like to receive some notification to my app and then let my app decide based on some data in the dictionary that is passed in with didReceiveRemoteNotification, whether or not to show the Alert or some user visible notification? Is this possible in ANY way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法控制通过应用程序推送的
UIAlertView
的外观。但服务器可能可以:尝试发送不带警报
信息的推送通知。请告诉我它是如何工作的。
泰
You cannot control appearance of
UIAlertView
about Push through your application. But may be server could: try to send Push-notification w/oalert
information.Tell me, please, how it works.
TY
距离这个问题提出已有10年了,还有17天。现在,从 iOS 10.0 开始,您就可以了。
It's 17 days until it's 10 years since this question was asked. Now, you can, since iOS 10.0`. ????
I just wrote an answer to how to get the userInfo in other delegate methods. In your specific case, you want to implement the userNotificationCenter(_:willPresent:withCompletionHandler:).
Get the
userInfo
dictionary in that delegate method by usingnotification.request.content.userInfo
. If you set a key/value such asforegroundNotification: true
in thedata
payload passed to APNs, your device can see that here.All you have to do is:
More advanced handling (sound, supporting iOS 10+, including deprecations)
Bear in mind
alert
has been deprecated in iOS 14, and you may want to add iOS version checks, sound, list.