我有一个ionic 应用程序.我用Xcode为iOS编译了这段代码,它很管用.我还为该应用程序创建了一个小部件.我的愿望是,如果应用程序以正常的应用程序图标打开,主屏幕应该会出现.然而,如果它是用小部件打开的,它将重定向到另一个页面.我怎么能做到这一点?我试了很多方法,但都找不到解决办法.

为此,我试图在TypeScrip端创建一个服务并在那里进行路由,但我不能在这里运行TypeScrip中的代码.

博士:

import { registerPlugin } from '@capacitor/core';
import { NavController } from '@ionic/angular';

// Define the interface
export interface MyServicePlugin {
  routeProfile(): any;
  routePage(): any;
}

// Implement the class
export class MyService implements MyServicePlugin {
  constructor(
    private navCtrl: NavController
  ) { }
  routeProfile() {
    console.log("sssssssss")
     return this.navCtrl.navigateForward(['/login-control']);
  }

  routePage() {
    console.log("ddddddd")
    return this.navCtrl.navigateForward(['/login-control']);
  }
}

const myService = registerPlugin<MyServicePlugin>('MyService');

export default myService;说

SWIFT代码:

import Foundation
import Capacitor

@objc(MyService)
public class MyService: CAPPlugin {

@objc func routePage(_ call: CAPPluginCall) {

}

@objc func routeProfile(_ call: CAPPluginCall) {
        if let viewController = self.bridge?.viewController {
        //viewController.performSegue(withIdentifier: "/login-control", sender: nil)
            call.resolve([:])
        } else {
            call.reject("NavController is not available.")
        }
    }
}

我在设备方面的结果:

To Native ->  MyService routeProfile 134138947

推荐答案

似乎没有什么问题.我想你忘了调用函数了.

调用ts文件中的函数:

await myService.routeProfile();

此外,您还可以发送参数.

在SWIFT中:

call.resolve(["xxx":"yyy"])

您可以在ts文件中获取此值.

let xVal = await myService.routeProfile();

Swift相关问答推荐

多个提取来计算核心数据中的记录

如何分解阿拉伯字母?

如何在SWIFT中使用DiscardingTaskGroup获得任务结果

了解SWIFT中的命名VS位置函数调用

如何在macOS中延迟退出应用程序的退出操作?

更改 SwiftUI 中按钮矩阵的填充 colored颜色

Xcode创建GitHub仓库,但未推送所有文件

如何在 SwiftUI 中为过渡动画保持相同的标识

如何在 Swift 中做类型安全的索引?

子视图未在父视图 SwiftUI 中触发禁用状态更新

为什么 SwiftUI 中 ForEach 的这个 Select 不起作用?

如何制作进度加载动画?

在 SwiftUI 中将属性显式设置为其默认值

如何在不提交到应用store 的情况下在本地运行我的应用

如何在 Swift 中使用子定义覆盖父类扩展

如何在 SwiftUI 中将图像传递到 2 个视图

从 Swift 列表中的行中检索值

如何让 SwiftUI 中的文本在旋转框架的同时侧向显示?

为什么swiftui中的导航视图栏那么大?

如何从 Button 获取标签名称?