应用程序终止时的

应用程序终止时的

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

问题描述

升级到 iOS 10 后,我遇到了关于推送通知的问题(我使用的是 Swift3).

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.

这是我的测试用例.

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

在该应用程序启动后 didFinishLaunchingWithOptions 被调用但 launchOptions 为空 所以我无法处理推送通知(但如果我从通知中心的通知打开应用程序或弹出通知 launchOptions 不为空)

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 ?

提前致谢.

推荐答案

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

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

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

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-应用程序

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

07-23 22:18