【发布时间】:2020-02-29 16:34:34
【问题描述】:
我正在寻找一种将事件从 iOS/Swift 传递到 Ionic/Capacitor 应用程序前端的方法,最终目标是改造此代码,以便我可以处理第 3 方推送通知提供程序。流程是应用程序加载通知数据并将其传递给我的 Capacitor 插件,以便我可以使用 bridge 方法(也许我可以直接从 AppDelegate 执行此操作?)并且在我的插件中我有一个可观察的准备接收然后将通知传递给根据 Capacitor 文档执行事件的方法,但是没有事件每次都被触发并且没有警报弹出,这可能是因为 AppDelegate 和插件在 webview 之前加载但在那个护理中我不确定如何处理这个。
AppDelegate.swift
func applicationDidBecomeActive(_ application: UIApplication) {
let nc = NotificationCenter.default
nc.post(name: Notification.Name("TestingEvents"), object: nil)
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was
}
MyPlugin.swift
public override func load() {
let nc = NotificationCenter.default
nc.addObserver(self, selector: #selector(handleSignal), name: Notification.Name("TestingEvents"), object: nil)
}
@objc func handleSignal() {
self.bridge.triggerWindowJSEvent(eventName: "myCustomEvent")
self.notifyListeners("myPluginEvent", data: [:])
}
还有我的 app.component.ts
window.addEventListener('myCustomEvent', () => {
console.log("ATTEMPTILE PUSH")
alert("myCustomEvent 2 ")
});
Plugins.myPlugin.addListener("myPluginEvent", (info: any) => {
console.log("myPluginEvent was fired");
alert("myPluginEvent 2 ")
});
【问题讨论】:
标签: ios swift ionic4 capacitor