gpt4 book ai didi

ios - 如何将 notification.userinfo 从 PushNotification 传递到 Swift 中的特定 View Controller

转载 作者:行者123 更新时间:2023-11-28 07:22:10 25 4
gpt4 key购买 nike

我有这样的代码。如果我收到推送通知并点击它,我想重定向到特定的 View Controller ,但我想将一个值(隐藏在通知中)传递给特定的 View Controller

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive, response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let application = UIApplication.shared

if(application.applicationState == .inactive)
{

LocalData.indexTabBar = nil
let storyboard = UIStoryboard(name: "Main", bundle: nil)
if LocalData.emailLogin != nil && LocalData.passwordLogin != nil && LocalData.tokenLogin != nil {

let initialViewController = storyboard.instantiateViewController(withIdentifier: "MainControllerIfSavedLogin") as! UITabBarController

initialViewController.selectedIndex = 2 //Selecting tab here
self.window?.rootViewController = initialViewController

} else{

let initialViewController = storyboard.instantiateViewController(withIdentifier: "loginViewController") as UIViewController

self.window?.rootViewController = initialViewController

}

self.window?.makeKeyAndVisible()

}

completionHandler()
}

最佳答案

得到它

let userInfo = response.notification.request.content.userInfo 

然后发送

let tab =  ------ as! MainControllerIfSavedLogin
let vc = tab.viewControllers!.first as! LoginViewController
vc.info = userInfo

class LoginViewController : UIViewController {
var info:[String:Any]?
}

关于ios - 如何将 notification.userinfo 从 PushNotification 传递到 Swift 中的特定 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57740676/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com