在 Ionic React 中收听 iOS 电容器通知

Listen to iOS Capacitor notifications in Ionic React

我正在使用 React 中的 Ionic 框架。我使用 Capacitor 从中创建了一个 iOS 应用程序。现在在 Capacitor 应用程序中,在 AppDelegate 中调用 application(_:open:options:) 时,电容器调用 handlerOpenUrl(_:_:) 方法,该方法又发布 notifications.

  func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    return CAPBridge.handleOpenUrl(url, options)
  }

  public static func handleOpenUrl(_ url: URL, _ options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool {
    NotificationCenter.default.post(name: Notification.Name(CAPNotifications.URLOpen.name()), object: [
      "url": url,
      "options": options
    ])
    NotificationCenter.default.post(name: NSNotification.Name.CDVPluginHandleOpenURL, object: url)
    CAPBridge.lastUrl = url
    return true
  }

现在,我想在我的 ionic React 代码库中收听这些 notifications,这样我就可以在 UI 上显示 urloptions

我找不到任何有关如何解决此问题的相关内容。

对于电容器通知使用 App plugin

import { Plugins } from '@capacitor/core';

const { App } = Plugins;

App.addListener('appUrlOpen', (data: any) => {
  console.log('App opened',  data.url, data.options);
});