关于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 iOSHowever, 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 iOSBoth 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的iOS和Android插件开发的各个页面,它们的外观会相同.另请注意,您所指的Wiki上的文本似乎是nearly on year old.