应用程序在后台swift 3时进行远程推送通知 [英] remote push Notification when app is in background swift 3

查看:326
本文介绍了应用程序在后台swift 3时进行远程推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个接收远程推送通知的应用程序. 我已经以这种方式实现了didReceiveRemoteNotification:

I have an app that receives remote push notification. I have implemented didReceiveRemoteNotification in this way:

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不会调用(我看不到打印内容"PUSH NOTIFICATION即将来临"),而且我也不明白为什么

In both cases(when app is in foreground and background) I have to show webview that add like child to root view(tabbar controller) but if app is in foreground then I have to show , before , an alert view. My problem is that if app is in foreground I haven't problems , but if app is in background didReceiveRemoteNotification doesn't call(I don't see the print "PUSH NOTIFICATION is coming" ) and I don't understand why.

你能帮我吗?

NB用于测试,我使用APN Tester( https ://itunes.apple.com/it/app/apn-tester-free/id626590577?mt = 12 )发送推送通知

N.B for testing I use APN Tester(https://itunes.apple.com/it/app/apn-tester-free/id626590577?mt=12) for send push notification

推荐答案

didReceiveRemoteNotification用于在应用程序活动时使用.

didReceiveRemoteNotification is meant to be used when the app is active.

当应用处于后台或处于非活动状态时,您可以通过按远程通知上的操作按钮将其激活.在您的应用程序委托中实现 userNotificationCenter(_:didReceive:withCompletionHandler :)

When the app is in the background or inactive, you can activate it by pressing the action button on the remote notification. Implement userNotificationCenter(_:didReceive:withCompletionHandler:) in your app delegate.

这篇关于应用程序在后台swift 3时进行远程推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆