首页 文章

管理推送通知

提问于
浏览
0

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

Unable to hide notification when app is running foreground

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

  • 删除委托方法func userNotificationCenter的实现(_ center:UNUserNotificationCenter,willPresent通知:UNNotification,withCompletionHandler completionHandler:@escaping(UNNotificationPresentationOptions) - > Void)

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

  • completionHandler([]) - 这不起作用 . 我试图通过“UNNotificationPresentationOptionNone”

Clear Notification

如何清除/删除列表中的已发送(一旦用户读取或取消)通知,并相应地更新徽章图标 .

谢谢

1 回答

  • 0

    Foreground Presentation Handling

    使用Urban Airship SDK在iOS10上处理前景呈现选项有两种方法 . 如果您在Urban Airship SDK上配置了UAPushNotificationDelegate实例,那么演示选项将被委派给presentationOptions并按推送进行处理 . 例如:

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

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

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

    UAirship.push().defaultPresentationOptions = []
    

    Clearing Notifications

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

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

相关问题