在动态框架中实现通知服务和内容扩展



我在演示应用程序中实现了Extension Notification ServiceNotification Content Extension,而且工作效果绝对很好。

现在,我必须在框架中实现它。意味着我正在研究动态框架,这些框架像聊天应用程序一样支持。在框架中,所有屏幕都是在编程中创建的,它不包含任何故事板或xib。

我已经设置了Notification Service ExtensionNotification Content Extension的所有必需配置,与框架中的演示应用相同。一切都与我的双重检查相同。

我正在努力实施Notification Service ExtensionNotification Content Extension

我是否需要以编程方式而不是故事板来创建Notification Content?我应该需要添加目标依赖性吗?我想念什么?

在拖动通知时,它不会向我显示通知内容。

以下是我目前用于测试本地通知的代码。此代码在Demo App中使用。

@available(iOS 10.0, *)
func scheduleNotification() {
    UNUserNotificationCenter.current().delegate = self
    let content = UNMutableNotificationContent()
    content.title = "Notification"
    content.body = "We will remind you that your notification demo is performed well."
    content.sound = UNNotificationSound.default()
    content.categoryIdentifier = "myNotificationCategory"
    content.userInfo = ["Image" as AnyHashable: "https://codepo8.github.io/canvas-images-and-pixels/img/horse.png"]
    let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
    let request = UNNotificationRequest(identifier: "request", content: content, trigger: trigger)
    UNUserNotificationCenter.current().add(request) { (error) in
        if error != nil {
            print("Error to add notification: (error!.localizedDescription)")
        } else {
            print("Notification added")
        }
    }
}

我也通过调试来测试它,但是didReceive(_ notification: UNNotification)也没有调用。

我被卡住了!请帮我?将不胜感激。

我在私人框架中添加了关于Notification Service ExtensionNotification Content Extension的观点。因此,您的框架包含sharedInstance,这就是为什么您不能在框架中实现两个扩展程序,因为它不允许。

因此,有解决方案可以创建一个与您的扩展方法相关的代码,该方法将是类方法。它包含填充您的通知服务的代码。

  1. 创建新的小框架,其中包含类方法和与Notification Content ExtensionNotification Service Extension相关的代码。

  2. 使用私人框架在您的应用程序中添加此框架。

  3. 在应用程序和实施方法中添加Notification Content ExtensionNotification Service Extension目标,将相对方法从应用程序调用到您的通知框架。

您将使用此解决方案获得解决方案,但是您还需要在应用程序中添加一个框架

最新更新