且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

应用终止时,iOS 10推送通知?

更新时间:2023-11-24 19:12:10

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

从图标启动应用程序时,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