【问题标题】:Managing Push notification管理推送通知
【发布时间】:2018-02-14 07:24:12
【问题描述】:

我正在使用 Urban Airship 在我的 iOS 10 (Swift) 应用程序中接收推送通知。我遇到以下问题,请求您帮助解决。

应用在前台运行时无法隐藏通知

为了隐藏通知,我尝试了以下任务..

  1. 移除委托方法 func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent 通知:UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)

  2. 我试图通过 completionHandler(UNNotificationPresentationOptionNone) 转义/隐藏通知 toast,但“UNNotificationPresentationOptionNone”不再可用。

  3. completionHandler([]) -- 这不起作用。 我试图在

  4. 中传递“UNNotificationPresentationOptionNone”

清除通知

如何从列表中清除/删除传递的(一旦用户阅读或取消)通知并相应地更新徽章图标。

谢谢

【问题讨论】:

  • @rmaddy 你能告诉我,当应用程序处于后台并收到通知时会执行哪个方法?

标签: ios swift notifications ios10


【解决方案1】:

前台演示处理

在 iOS10+ 上,使用 Urban Airship SDK 可以通过两种方式处理前台呈现选项。如果您在 Urban Airship SDK 上配置了 UAPushNotificationDelegate 的实例,则演示选项将委托给 presentationOptions 并在每次推送时处理。例如:

@available(iOS 10.0, *)
func presentationOptions(for notification: UNNotification) -> UNNotificationPresentationOptions {
    return [.alert]
}

您可以返回 [] 以不显示任何内容。

否则,如果您没有配置上述代理,您可以通过设置defaultPresentationOptions 来禁用所有前台演示选项。

UAirship.push().defaultPresentationOptions = []

清除通知

在 iOS10+ 上,您可以通过 UNUserNotificationCenter 的共享实例清除应用的通知,该实例提供了 removeAllDeliveredNotifications() 方法。为了保持与旧版本 iOS 的兼容性,您可以回退到将徽章设置为零——有关 here 的更多信息。

if #available(iOS 10.0, *) {
    UNUserNotificationCenter.current().removeAllDeliveredNotifications()
} else {
    UIApplication.shared.applicationIconBadgeNumber = 0;
};

【讨论】:

  • 你能告诉我当应用程序在后台并收到通知时执行哪个方法吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多