簡體   English   中英

在 Ionic React 中收聽 iOS 電容器通知

[英]Listen to iOS Capacitor notifications in Ionic React

我正在使用 React 中的 Ionic 框架。 我使用電容器從它創建了一個 iOS 應用程序。 現在在電容器應用程序中,在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 插件

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

const { App } = Plugins;

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM