PhoneGap插件,为什么每个平台(Android,iOS)的Javascript部分不同?

关于PhoneGap插件的编码,PhoneGap Wiki说:

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.

我的问题是:为什么每个平台需要2个Javascript文件?
这是插件的Javascript部分的样子:

var FilePlugin = function() {};
FilePlugin.prototype.read = function(data, successCallback, failureCallback) {
return PhoneGap.exec(    
        successCallback,   
        failureCallback,    
        'FilePlugin',  
        'read',              
        [data]);       
};
PhoneGap.addConstructor(function() {
PhoneGap.addPlugin("FilePlugin", new FilePlugin());
});

我在那里看不到平台相关的内容,那么为什么维基说每个平台都需要自己的Javascript文件?

可能是我错了,所以我需要您的帮助;)

谢谢

解决方法:

我认为exec API有所不同,但是自从我进行任何PhoneGap开发以来,他们一直在努力使其相同.而且,如果您查看关于PhoneGap.exec的iOSAndroid插件开发的各个页面,它们的外观会相同.另请注意,您所指的Wiki上的文本似乎是nearly on year old.

上一篇:ionic打包app——以安卓版本为例 辛苦之路~~~


下一篇:javascript-如何在Cordova PhoneGap应用程序中打开设置-> iPhone的隐私