如果应用程序在后台,我发送一个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])
}
}
}
如果应用程序被杀,我想得到同样的东西
答案 0 :(得分:1)
在appdelegate的applicationWillTerminate
中尝试使用此方法,当应用程序被杀死时会调用此方法。