我有一个可以接收远程推送通知的应用程序。
我已经实施了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,但如果应用程序位于前台,那么我必须在之前显示警报视图。
我的问题是,如果应用程序位于前台,我没有问题,但如果应用程序位于后台didReceiveRemoteNotification
不打电话(我没有看到打印“推送通知即将到来”),我不明白为什么。
你能帮助我吗?
N.B 进行测试时我使用 APN 测试仪(https://itunes.apple.com/it/app/apn-tester-free/id626590577?mt=12 https://itunes.apple.com/it/app/apn-tester-free/id626590577?mt=12) 用于发送推送通知
didReceiveRemoteNotification
旨在在应用程序运行时使用active.
当应用程序位于背景或处于非活动状态,您可以通过按远程通知上的操作按钮来激活它。实施userNotificationCenter(_:didReceive:withCompletionHandler:) https://developer.apple.com/reference/usernotifications/unusernotificationcenterdelegate/1649501-usernotificationcenter在您的应用程序委托中。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)