gpt4 book ai didi

ios - 一个应用程序中的多个Notification Service Extension

转载 作者:行者123 更新时间:2023-12-01 15:18:30 32 4
gpt4 key购买 nike

是否可以在一个应用程序中添加多个Notification Service Extension?如果是,那么如何识别将使用哪个应用程序?

基本上,我的应用程序有两个服务提供者,并且它们都有自己的通知服务扩展有效负载,因此有什么方法可以添加两个不同的通知服务扩展并根据serviceProvider ==“1”可以告诉应用程序运行serviceProvider 1的扩展

最佳答案

NotificationServiceExtension
该文档没有对此发表任何评论。在我的测试中,它不起作用。所有通知都通过单个NotificationServiceExtension处理。
NotificationContentExtension
对于NotificationContentExtension,文档说:

You may add more than one notification content app extension to yourproject, but each one must support a unique set of notificationcategories. You specify the categories for your app extension in itsInfo.plist file, as described in Declare the Supported NotificationTypes.


Customizing the Appearance of Notificationsdocs


我验证了☝️并且有效! FWIW,您可以将一个Notification Content Extension用于多个类别。

UNNotificationExtensionCategory (Required)

A string or an array of strings. Each string contains the identifierof a category declared by the app using the UNNotificationCategoryclass.


还值得一提的是, NotificationServiceExtension的默认plist设置如下所示:
enter image description here
它不会将自己与任何给定的类别相关联。我尝试添加 NSExtensionAttributes以及 UNNotificationCategoryExtension键值。但是即使编译了,也没有用!我认为Apple决定如何使用Notification Service Extension的方式基于以下两个领域:
  • 其bundleID前缀为apns-topic
  • 的目标
  • 必须始终设置为NSExtensionPointIdentifercom.apple.usernotifications.service字段。对于今天的扩展名或内容通知扩展名等,此值是不同的。

  • 因此,如果您有两个服务扩展,则系统无法决定应显示哪个服务扩展
    但是, NotificationContentExtension的默认plist设置确实具有 UNNotificationCategoryExtension key ,其值包括:
    enter image description here

    再考虑一下这个问题,如果一个应用程序有5个不同的类别,并且每个类别都有一个服务扩展,并且一次接收到它们,那么它将启动5个不同的进程(例如5个并行的 didFinishLaunchingWithOptions回调。每个类别一个)和流程),这对操作系统不利。
    虽然不确定,但 documentation on Signal's NotificationService class支持该理论。
    // Note that the NSE does *not* always spawn a new process to
    // handle a new notification and will also try and process notifications
    // in parallel. `didReceive` could be called twice for the same process,
    // but will always be called on different threads. To deal with this we
    // ensure that we only do setup *once* per process and we dispatch to
    // the main queue to make sure the calls to the message fetcher job
    // run serially.
    NotificationContentExtension并非如此。它不能一次处理5个contentExtensions。因为它是一个由主线程控制的UI功能。

    关于ios - 一个应用程序中的多个Notification Service Extension,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41377967/

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