Khushboo Motwani Khushboo Motwani - 5 months ago 39
iOS Question

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.

Answer

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();"];