首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >远程推送通知时,应用程序是在后台迅速3

远程推送通知时,应用程序是在后台迅速3
EN

Stack Overflow用户
提问于 2016-11-07 22:18:07
回答 2查看 10.3K关注 0票数 3

我有一个应用程序,接收远程推送通知。我以这种方式实现了didReceiveRemoteNotification

代码语言:javascript
复制
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)发送推送通知。

EN

回答 2

Stack Overflow用户

发布于 2016-11-07 22:41:30

didReceiveRemoteNotification是指当应用程序是active时使用的。

当应用程序处于背景或非活动状态时,您可以按下远程通知上的操作按钮来激活它。在应用程序委托中实现*didReceive:withCompletionHandler:)

票数 2
EN

Stack Overflow用户

发布于 2020-08-25 11:38:02

在AppDelegate.swift中:

代码语言:javascript
复制
 func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
    // make your function call
 }

didReceive 的意思是:当您的应用程序是后台时,单击通知didReceive正在工作

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40475694

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档