Issue
I have an Ionic application. I compiled this in Xcode for iOS and it works. I also created a widget for this application. My wish is that if the application opens with the normal application icon, the main screen should appear. However, if it is opened with a widget, it will redirect to another page. How can I do that? I tried many ways but couldn't find a solution.
For this, I tried to create a service on the Typescript side and do the routing there, but I cannot run the codes in typescript here.
Ts:
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 Code:
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.")
}
}
}
`
My Result in device:
To Native -> MyService routeProfile 134138947
Solution
There doesn't seem to be a problem. I think you forgot to call the function.
Call func in ts file:
await myService.routeProfile();
Additionally, you can send parameters.
In swift:
call.resolve(["xxx":"yyy"])
You can get this value in ts file.
let xVal = await myService.routeProfile();
Answered By - fbdev1907
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.