Why do you need 2 Javascript files for cross-platform Cordova plugin?

醉酒当歌 提交于 2019-12-08 05:42:16

问题


In this article here, I quote:

Catch about different Platforms Before it comes as a surprise to you, let me clarify some things. Say you are developing a Phonegap plugin for 2 platforms: iOS and Android. One might assume that we need to churn out: a single JavaScript file that will be used on both iOS and Android; one Java file for Android One .h and One .m for iOS
However, in reality you will need to churn out: one Javascript file for Android, along with a Java file for Android; a different Javascript file for iOS, alone with pair of .h and .m file for iOS. Both Javascript files can (and should) have the same interface for the developer who consumes it, but the implementations of each interface would be different.

Why would you need 2 Javascript files, if the native methods are all named the same? I've created an iOS plugin (with a corresponding .js file) and now that I'm creating the Android side, I can't see why I would need a separate .js for the Android side. Any ideas why they stress this for no particular reason?


回答1:


Well it depends on what version of PhoneGap/Apache Cordova you are using. In previous version the PhoneGap.exec() method signature was different between iOS and Android. As of 1.7.0 and probably as early as 1.5.0 the method signature is the same. You should be able to use the same .js file for your plugin regardless of the platform you are running on.

cordova.exec(success, fail, service, action, args);

I will create an issue to clean up the wiki instructions.



来源:https://stackoverflow.com/questions/10810568/why-do-you-need-2-javascript-files-for-cross-platform-cordova-plugin

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