城市飞艇收到从未通知过的背景通知 [英] Urban Airship receivedBackgroundNotification never called

查看:80
本文介绍了城市飞艇收到从未通知过的背景通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读所有指南,并检查了Internet上的数百篇文章之后,我很确定永远不会调用receiveBackgroundNotification方法.

After reading all the guides, and after checking hundred of articles on the internet, I'm quite sure that the method receivedBackgroundNotification is never called.

一切正常,但是当应用程序在后台运行时,会显示一条通知,并且永远不会调用此方法.似乎不可能使其正常工作.

Everything works perfect, but when the app is in background, a notification is shown and this method never is called. Seems to be impossible to get it working.

假设所有正常操作和基本配置均已完成并且可以正常工作,那么该库可以用来拦截和管理后台推送通知吗?

Assuming all the normal operations and the basic configuration is well done and is working, what can I do to intercept and manage background push notifications with this library?

我将不胜感激.

推荐答案

在Urban Airship iOS SDK v.13.4.0中,如果 func receiveBackgroundNotification(_ notificationContent:UANotificationContent,completeHandler:@escaping(UIBackgroundFetchResult)-> Void)不会被调用,如果您将通知显示为警报,则可以在 func ReceivedNotificationResponse(_ notificationResponse:UANotificationResponse,completeHandler:@escaping()-> Void)中处理通知.请记住,您只能使用 actionIdentifier == UNNotificationDefaultActionIdentifier (用户从通知界面打开应用程序)来处理通知.

In Urban Airship iOS SDK v.13.4.0 if func receivedBackgroundNotification(_ notificationContent: UANotificationContent, completionHandler: @escaping (UIBackgroundFetchResult) -> Void) is not called you can handle notifications in func receivedNotificationResponse(_ notificationResponse: UANotificationResponse, completionHandler: @escaping () -> Void) if you display notifications as alerts. Remember that you should only handle the notifications with actionIdentifier == UNNotificationDefaultActionIdentifier (the user opened the app from the notification interface).

这是 UAPushNotificationDelegate 实现的示例:

extension MyPushNotificationDelegate: UAPushNotificationDelegate {
    public func receivedForegroundNotification(_ notificationContent: UANotificationContent, completionHandler: @escaping () -> Void) {
        completionHandler()
    }

    public func receivedBackgroundNotification(_ notificationContent: UANotificationContent, completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        completionHandler(.newData)
    }

    public func receivedNotificationResponse(_ notificationResponse: UANotificationResponse, completionHandler: @escaping () -> Void) {
        guard notificationResponse.actionIdentifier == UNNotificationDefaultActionIdentifier else {
            completionHandler()
            return
        }
        someFunc() {
            completionHandler()
        }
    }

    public func extend(_ options: UNNotificationPresentationOptions = [], notification: UNNotification) -> UNNotificationPresentationOptions {
        [.alert, .badge, .sound]
    }
}

这篇关于城市飞艇收到从未通知过的背景通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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