1

私は5つのタブを持つtabBarを持つアプリケーションを持っています。最初のものは「FirstView」と呼びましょう - 次のコードがあります:

    override func viewWillAppear(_ animated: Bool) {
            ...
            NotificationCenter.default.addObserver(self, selector: #selector(self.catchIt), name: NSNotification.Name(rawValue: "myNotif"), object: nil)
        }



        override func viewWillDisappear(_ animated: Bool) {
            ...
            NotificationCenter.default.removeObserver(self)
        }

    override func viewDidAppear(_ animated: Bool) {
            ...
            NotificationCenter.default.post(name: Notification.Name(rawValue: "myNotif"), object: nil, userInfo: userInfo as [AnyHashable: Any])
        }
    }

私はまた、このビットのコードを持つ didReceiveRemoteNotification にコードを持っています:

NotificationCenter.default.post(name: Notification.Name(rawValue: "myNotif"), object: nil, userInfo: userInfo as [AnyHashable: Any])

そして、catchIt() とリダイレクト ロジックを定義する UIViewController 拡張機能を取得しました。

 func catchIt(_ userInfo: Notification) {
        let notification = userInfo.userInfo 
            if (path == "account.balance") {
                let vc: ProfileViewController = storyboard!.instantiateViewController(withIdentifier: "account.balance") as! ProfileViewController
                self.navigationController?.pushViewController(vc, animated: true)
//..and so on for other paths
      }
 }

このコードには 2 つの問題があります。1) リダイレクトは、最後に開いたビューが FirstView である場合にのみ機能します。それが他のビューの場合、プッシュ通知をテーピングするときにリダイレクトされることはありません

2)リダイレクトされたときに履歴を取得しましたが、宛先コントローラーがFirstViewsとは異なる別のタブにある場合でも、FirstViewまで追跡します(最初に必要なタブにリダイレクトしてから宛先コントローラーにリダイレクトしようとしましたが、それでもFirstViewのタブからトラックを提供します)

私も didReceiveRemoteNotification を使用しようとしました - すべてのリダイレクトロジックをそれに書きましたが、うまくいきませんでした

アドバイスをいただければ幸いです

4

1 に答える 1