且构网

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

应用程序被杀死时的 iOS 推送通知

更新时间:2022-12-21 13:22:31

当app处于killed状态时,不会调用didReceiveRemoteNotification方法.然后点击通知应用程序(_:didFinishLaunchingWithOptions) 方法将被调用.如果通过点击通知启动应用程序,launchOption 包含有效负载.为此,在此方法中编写给定的代码:

When app is in killed state, didReceiveRemoteNotification method will not be called. Then on the tap of notification application(_:didFinishLaunchingWithOptions) method will be called. launchOption contains the payload if app is launched by tap on notification. For that write the given code in this method:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
       if launchOptions != nil{
         let userInfo = launchOptions? 
         [UIApplicationLaunchOptionsKey.remoteNotification]
          if userInfo != nil {
        // Perform action here
         }
    }

您的所有负载数据都将在 launchOptions 中可用?[UIApplicationLaunchOptionsKey.remoteNotification] &从那里执行您的应用逻辑(导航..).

All your payload data will be available in launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] & perform your app logic(navigation..) from there.

请参阅此链接以获得有效的推送通知处理

Refer this link for effective push notifications handling