【发布时间】:2016-11-07 22:18:07
【问题描述】:
我有一个接收远程推送通知的应用程序。
我以这种方式实现了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 不会调用(我没有看到打印“推送通知即将到来”)而且我不明白为什么.
你能帮帮我吗?
注意测试我使用 APN Tester(https://itunes.apple.com/it/app/apn-tester-free/id626590577?mt=12) 发送推送通知
【问题讨论】:
-
您是否在应用的后台模式功能中指定了“远程通知”?此外,当您的应用处于后台时,您无法显示 Web 视图或以其他方式强制您的应用进入前台。
-
推送有两种类型,一种是一直发送给用户,一种是在用户看不到的情况下发送给应用程序。如果您的应用程序在后台,您可以使用第二种类型的推送。但是,正如 Paulw11 指出的那样,鉴于您对为什么要使用它的解释,这是没有意义的,因为您无法强制后台应用程序进入前台,即后台应用程序无法显示任何 GUI(除了发布本地通知)。
标签: ios iphone swift push-notification apple-push-notifications