use*_*079 5 iphone objective-c ios swift
是否可以在一个应用程序中添加多个Notification Service Extension?如果是,那么如何识别将使用哪个应用程序?
基本上,我的应用程序有两个服务提供者,并且它们都有自己的通知服务扩展有效负载,因此有什么方法可以添加两个不同的通知服务扩展并根据serviceProvider ==“ 1”可以告诉应用程序运行serviceProvider 1的扩展
文档对此没有任何说明。在我的测试中它不起作用。所有通知均通过单个NotificationServiceExtension.
对于NotificationContentExtension文档说:
\n\n您可以向您的项目添加多个通知内容应用扩展\n,但每个扩展都必须支持一组唯一的通知类别。\n 您可以在应用扩展的 Info.plist 文件中指定其类别,如声明支持的通知类型中所述。
\n
\n\n\n
我验证了 \xe2\x98\x9d\xef\xb8\x8f 并且它有效!FWIW,您可以对多个类别使用单个通知内容扩展。
\n\n\nUNNotificationExtensionCategory(必需)
\n一个字符串或字符串数组。每个字符串都包含应用程序使用 UNNotificationCategory 类声明的类别的标识符。
\n
还值得一提的是 a 的默认 plist 设置NotificationServiceExtension如下所示:
它不将自己与任何给定的类别相关联。我尝试添加NSExtensionAttributes以及键值UNNotificationCategoryExtension。但即使它编译了,它也不起作用!我认为苹果决定如何使用通知服务扩展的方式基于这两个字段:
apns-topicNSExtensionPointIdentifer必须始终设置为 的字段com.apple.usernotifications.service。对于今天的扩展或内容通知扩展等,此值是不同的。因此,如果您有两个服务扩展,那么系统无法决定应该显示哪一个
\n但是 a 的默认 plist 设置NotificationContentExtension确实包含UNNotificationCategoryExtension键、值:
还要更多地考虑这一点,如果一个应用程序有 5 个不同的类别,并且每个类别都有一个服务扩展并一次接收所有这些类别,那么它将启动 5 个不同的进程(考虑 5 个并行didFinishLaunchingWithOptions回调。每个类别一个,进程),这对操作系统不利。
虽然不确定,但Signal 的 NotificationService 类的文档支持这一理论。
\n\n\nRun Code Online (Sandbox Code Playgroud)\n// Note that the NSE does *not* always spawn a new process to\n// handle a new notification and will also try and process notifications\n// in parallel. `didReceive` could be called twice for the same process,\n// but will always be called on different threads. To deal with this we\n// ensure that we only do setup *once* per process and we dispatch to\n// the main queue to make sure the calls to the message fetcher job\n// run serially.\n
对于 来说情况并非如此NotificationContentExtension。它无法同时处理 5 个 contentExtensions。因为它的 UI 功能由主线程控制。
| 归档时间: |
|
| 查看次数: |
224 次 |
| 最近记录: |