[英]Listen to iOS Capacitor notifications in Ionic React
I'm working with Ionic framework in React.我正在使用 React 中的 Ionic 框架。 I've created an iOS app from it using the Capacitor.
我使用电容器从它创建了一个 iOS 应用程序。 Now in the Capacitor app, in
AppDelegate
when application(_:open:options:)
is called, capacitor calls a handlerOpenUrl(_:_:)
method which in turn posts the notifications
.现在在电容器应用程序中,在
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
}
Now, I want to listen to these notifications
in my ionic react codebase so I can show the url
and options
on the UI.现在,我想在我的 ionic react 代码库中收听这些
notifications
,以便在 UI 上显示url
和options
。
I couldn't find any relevant content on how to resolve this.我找不到任何有关如何解决此问题的相关内容。
For Capacitor notification use App plugin对于电容器通知,请使用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.