gpt4 book ai didi

ios - UNNotificationServiceExtension - 在应用程序处于事件状态时隐藏

转载 作者:行者123 更新时间:2023-11-28 13:50:55 25 4
gpt4 key购买 nike

我正在使用 UNNotificationServiceExtension 将图像添加到 iOS APNS 通知。它运行良好,除了即使应用程序处于事件状态(在前台)也会显示通知。当应用处于事件状态时,我希望使用 toast 处理通知,而不是在事件应用的顶部显示标准 iOS 通知。

问:有没有办法从 Notification Service Extension 中检测应用程序的状态,并在应用程序处于事件状态时阻止通知显示?

最佳答案

基于 Apple 的 documentation默认情况下,应用处于事件状态时不应显示通知。

If your app is in the foreground when a notification arrives, the shared user notification center calls this method to deliver the notification directly to your app. If you implement this method, you can take whatever actions are necessary to process the notification and update your app. When you finish, call the completionHandler block and specify how you want the system to alert the user, if at all.

如果您使用通知服务扩展并不重要 - 通知最终总是由应用程序处理,不过可以先使用扩展来修改它。

试试这个代码(事实上,因为通知会在应用程序处于事件状态时出现,你可能在某个地方实现了这个方法 - 如果你不需要它,你可以删除它)。

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {

// Perform additional handling of the notification, if needed.

completionHandler([])
}

关于ios - UNNotificationServiceExtension - 在应用程序处于事件状态时隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54614928/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com