应用终止时,iOS 10推送通知? [英] iOS 10 push notification when app terminated?

查看:123
本文介绍了应用终止时,iOS 10推送通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升级到iOS 10后,我会遇到有关推送通知的问题(我正在使用Swift3).

在正常情况下,当应用程序打开或应用程序仍处于后台时,所有功能也都可以正常运行(可以接收推送通知并更新数据).

但是当应用程序终止时,当应用程序处于活动状态时,我无法处理推送通知.

这是我的测试用例.

  1. 编辑方案以等待可执行文件启动.
  2. 双击主屏幕按钮并向上滑动应用程序.
  3. 运行Xcode,直到显示等待应用程序启动".
  4. 测试从服务器发送推送通知.
  5. 设备收到推送通知.
  6. 从应用程序图标启动应用程序.

启动该应用程序并调用 didFinishLaunchingWithOptions之后,但是launchOptions消失为空,因此我无法处理推送通知(但是如果我从通知中心的通知中打开应用程序,或者弹出通知launchOptions不为null)/p>

有人有什么想法要检查这个问题吗?

谢谢.

解决方案

您需要通过点击通知托盘中的推送通知来打开应用程序.

从图标启动应用程序时,launchOptions将为nil.从推送通知中启动将为您提供launchOptions.

https://developer.apple.com/reference/uikit/uiapplicationdelegate/1622921-应用程序

I'm face the problem after upgraded to iOS 10 about push notification (I am using Swift3).

In normal case when application open or application still in background everything work as well (can receive push notification and update data as my logic).

But when application is terminated i can't handle push notification when application become active.

Here is my test case.

  1. Edit Scheme to Wait for executable to be launched.
  2. Double press home button and swipe application up.
  3. Run Xcode wait until "Wait for application to launch" shown.
  4. Test send push notification from server.
  5. Device received push notification.
  6. Start application from application icon.

After that application start and didFinishLaunchingWithOptions being called but launchOptions aways null so i can't handle push notification (But if i open application from notification in notification center or popup notification launchOptions is not null)

Does anybody has any idea to check this problem ?

Thank you in advance.

解决方案

You need to open the application by tapping the push notification in the notification tray.

When you launch the application from the icon, launchOptions will be nil. Launching from the push notification will provide you launchOptions.

https://developer.apple.com/reference/uikit/uiapplicationdelegate/1622921-application

这篇关于应用终止时,iOS 10推送通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆