gpt4 book ai didi

ios - 当我收到 firebase 通知时打开链接

转载 作者:行者123 更新时间:2023-11-29 00:01:22 24 4
gpt4 key购买 nike

如果应用程序在后台,则使用 firebase 发送通知我收到通知并使用以下代码打开链接

func application(_ application: UIApplication, didReceiveRemoteNotification data: [AnyHashable : Any]) {
// Print notification payload data
print("Push notification received: \(data)")
application.applicationIconBadgeNumber = 0
let aps = data[AnyHashable("aps")] as? NSDictionary
if let title = (aps?.value(forKey: "alert") as? NSDictionary)?.value(forKey: "title"){
var get_data = String()
if UserDefaults.standard.object(forKey: "titleList") != nil{
get_data = UserDefaults.standard.value(forKey: "titleList") as! String
}
if get_data != ""{
UserDefaults.standard.set(get_data+" ,"+(title as! String), forKey: "titleList")
}else{
UserDefaults.standard.set((title as! String), forKey: "titleList")
}
}
if let body = (aps?.value(forKey: "alert") as? NSDictionary)?.value(forKey: "body"){
var get_data = String()
if UserDefaults.standard.object(forKey: "bodyList") != nil{
get_data = UserDefaults.standard.value(forKey: "bodyList") as! String
}
if get_data != ""{
UserDefaults.standard.set(get_data+" ,"+(body as! String), forKey: "bodyList")
}else{
UserDefaults.standard.set((body as! String), forKey: "bodyList")
}
}

if let url = aps?.value(forKey: "url") as? String{
print("get url:", url)
var get_data = String()
if UserDefaults.standard.object(forKey: "urlList") != nil{
get_data = UserDefaults.standard.value(forKey: "urlList") as! String
}
if get_data != ""{
UserDefaults.standard.set(get_data+" ,"+url, forKey: "urlList")
}else{
UserDefaults.standard.set(url, forKey: "urlList")
}
if url != ""{
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "subPage"), object: nil, userInfo: ["url":url])

}

}
}

如果应用程序被杀死,我想得到同样的东西

最佳答案

在 appdelegate 的 applicationWillTerminate 中试试这个,当应用程序被杀死时调用这个方法。

关于ios - 当我收到 firebase 通知时打开链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49426848/

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