我有一个应用程序,接收远程推送通知。我以这种方式实现了didReceiveRemoteNotification:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
print("PUSH NOTIFICATION is coming")
let state: UIApplicationState = UIApplication.shared.applicationState
let inBackground = state == .background
let dizionario = userInfo["aps"]! as! NSDictionary
let alert = dizionario["alert"]! as! String
print(alert)
if(!inBackground){
print("APP IN FOREGROUND")
//show alert view and the if user tap 'ok' show webview
}
else{
print("APP IS BACKGROUND")
//SHOW WEBVIEW
}
}在这两种情况下(当应用程序位于前台和后台时),我必须显示webview,该视图将像子控件一样添加到根视图(选项卡控制器),但如果应用程序位于前台,则必须在此之前显示警告视图。我的问题是,如果app在前台,我就没有问题,但是如果app在后台,didReceiveRemoteNotification就不会调用(我没有看到打印“推送通知即将到来”),我也不明白为什么。
你能帮帮我吗?
注:对于测试,我使用APN (https://itunes.apple.com/it/app/apn-tester-free/id626590577?mt=12)发送推送通知。
发布于 2016-11-07 22:41:30
didReceiveRemoteNotification是指当应用程序是active时使用的。
当应用程序处于背景或非活动状态时,您可以按下远程通知上的操作按钮来激活它。在应用程序委托中实现*didReceive:withCompletionHandler:)。
发布于 2020-08-25 11:38:02
在AppDelegate.swift中:
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
// make your function call
}didReceive 的意思是:当您的应用程序是后台时,单击通知didReceive正在工作
https://stackoverflow.com/questions/40475694
复制相似问题