How do I write basic “Hello World” java script plugin in PhoneGap?

穿精又带淫゛_ 提交于 2019-12-05 16:19:01

You can't make any calls to cordova until the deviceready event fires. Do:

 document.addEventListener("deviceready", function() {
    cordova.exec(null,null,"MyPluginClass","someMethod",[]);
 }, false);

Edit:

For the example call listed above, you'd need an Objective-C class that looks like:

@interface MyPluginClass : CDVPlugin

- (void)someMethod:(CDVInvokedUrlCommand*)command;

@end

Note the name of the class, and name of the method, which match the call to cordova.exec

Another Edit:

Your config.xml should look like the following:

<plugin name="MyPluginClass" value="MyPluginClass" />

(these don't necessarily have to be the same, but name should match the reference in the third argument of the javascript call, and value should match the name of your Objective-C class.

For full documentation on developing a plugin for iOS, check out the guide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!