Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to call a javascript function from my custom CDVPlugin class (Objective C Language)

I have created a custom (CDVPlugin) Plugin in Cordova app.

Through that plugin if javascript file calls a method which is declared in CDVPlugin then i can easily send response through

CDVPluginResult *pluginResult = nil;
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[NSString stringWithFormat:@"%@",deviceUUIDString]];
self.delegateCallbackId=command.callbackId;
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];

But how to call a javascript function from my custom CDVPlugin class.

like image 810
Khushboo Motwani Avatar asked Jun 13 '26 01:06

Khushboo Motwani


1 Answers

I found the answer if we want to call any javascript method call it with evalJs which is declared in CDVCommandDelegateClass and can write the name of the function as string with semicolon

In Cordova : we can use evaluateJavaScript method like this

[self.commandDelegate evalJs:@"callCustomMethodJs();"];

like image 76
Khushboo Motwani Avatar answered Jun 15 '26 15:06

Khushboo Motwani