San*_*yap 5 apn push-notification ios remote-notifications
我有一个ios应用程序,从服务器发送通知时我将远程通知发送到哪里,我正在设置内容-available = 1且声音=“” 在IOS设备上使用时
applicaiton(didReceiveRemoteNotification:fetchCompletionHandler :)
我看到应用程序在后台运行时到达此方法,但是在关闭应用程序时未调用此方法,但是在关闭应用程序时未调用该方法
applicaiton(didReceiveRemoteNotification:fetchCompletionHandler :)
我在此方法中的处理程序是
let userInfoDic = userInfo as NSDictionary as? [String: Any]
let cato = userInfoDic?["cato"] as? String
if cato == "message" {
let state: UIApplicationState = UIApplication.shared.applicationState
if state == .active{
print("Application is Active Socket IO will Handle This")
}else{
let apnMessage = userInfoDic?["apnMessage"] as? [String: Any]
if (apnMessage == nil){
print("Error Fetching Message")
}else{
let count = UserDefaults.standard.integer(forKey:"TotalUnredMessage")
DispatchQueue.main.async {
UIApplication.shared.applicationIconBadgeNumber = count + 1
}
UserDefaults.standard.set(count, forKey: "TotalUnredMessage")
}
}
Run Code Online (Sandbox Code Playgroud)
因此,即使关闭了应用程序,我也应该更改此方法才能运行
谢谢
当应用程序关闭时,didReceiveRemoteNotification方法将不会调用。
但是您可以在appdelegate的didFinishWithLaunchOptions方法中检查launchOptions以了解天气是否已从通知启动应用程序,并相应地执行任务。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
if launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] != nil {
// Do your task here
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8811 次 |
| 最近记录: |