0

I am facing some Objective-C lackiness of knowledge in my PhoneGap App.

I have a library that I need to implement in Objective-C. This Library has some callbacks that I receive in a delegate Class ( called CCController ) :

[MyLib sharedInstance].delegate = self;

This Class is instanciated in the AppDelegate.m like this :

CCController *myClass = [CCController alloc];
[myClass init];

Then, when my Lib sends events, the functions in my CCController are called. I need, at this point, to call my Javascript functions with a parameter.

How can I implement this ?

I have tried calling a function in AppDelegate.m which contains this :

NSString* jsString = [NSString stringWithFormat:@"myJSFunction(\"%@\");", stringParameter];
[self.viewController.webView stringByEvaluatingJavaScriptFromString:jsString];

But without success, nothing is called in my JS...

How can I implement this ? Thanks for help :)

1 Answer 1

7

You have to create a plugin and put the native code there instead using it in the AppDelegate.m.

From the plugin class you can do this:

NSString* jsString = [NSString stringWithFormat:@"myJSFunction(\"%@\");", stringParameter];
[self.webView stringByEvaluatingJavaScriptFromString:jsString];

Plugin development guide

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks, I didn't know this and it is not mentionned in the documentation. Now I want to know what is the best way to call functions in my Plugin Class from my CCController ?
I don't understand the question, js functions? Or native functions
The native code in my CCController class have to call natives functions in my Plugin class, so that I have access to the webView to call my javascript functions then.
If you tell me the library you are using I can take a look, but you can just use [self.webView stringByEvaluatingJavaScriptFromString:jsString]; whenever you want to call a js funcion
I want to call a function into the plugin from another Objective-C class. How can I do this (thanks for help)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.