Tôi đang làm việc trên plugin tạo tùy chỉnh plugin Phonegap/Cordova (phiên bản 2.9.0) cho ứng dụng iOS. bước của tôi như sau:Plugin PhoneGap cho ios quay lại FAILED pluginJSON
Tôi tạo ra một tập tin HelloPlugin.js và sao chép nó dưới www/js/thư mục, có mã của nó:
var HelloPlugin = { callNativeFunction: function (success, fail, resultType) { alert('a'); return Cordova.exec(success, fail, "HelloPlugin", "nativeFunction", ['1']); } };
Tôi tạo ra HelloPlugin.h và HelloPlugin. m file trong thư mục plugins, mã:
// .h #import <Cordova/CDVPlugin.h> @interface HelloPlugin : CDVPlugin - (void)nativeFunction:(CDVInvokedUrlCommand*)command; @end // .m #import "HelloPlugin.h" @implementation HelloPlugin - (void)nativeFunction:(CDVInvokedUrlCommand*)command { NSLog(@"Hello, this is a native function called from PhoneGap/Cordova!"); } @end
tôi thêm vào sau mã để config.xml file:
<feature name="HelloPlugin"> <param name="ios-package" value="CDVPlugin"/> </feature>
Cuối cùng tôi sửa đổi index.html theo cách sau:
- Script tham khảo thêm.()
mã JS thêm:
function callNativePlugin(returnSuccess) { HelloPlugin.callNativeFunction(nativePluginResultHandler, nativePluginErrorHandler, returnSuccess); } function nativePluginResultHandler (result) { alert("SUCCESS: \r\n"+result); } function nativePluginErrorHandler (error) { alert("ERROR: \r\n"+error); }
Hai nút thêm và chức năng gọi là:
"callNativePlugin ('thành công');" "callNativePlugin ('error');"
Tôi hy vọng đây là những điều cần thiết duy nhất tôi cần phải làm gì để kích hoạt plugin.
Sự cố: Trong khi chạy ứng dụng, tôi nhận được lỗi FAJED pluginJSON trên bảng điều khiển.
Output:
- [CDVCommandQueue executePending] [Đường dây 116] FAILED pluginJSON = [ "HelloPlugin2650437", "HelloPlugin", "nativeFunction", [ "1", "1", "1" ] ]
Tôi đã làm sai điều gì, vui lòng cho tôi biết. Tôi thực sự đánh giá cao nỗ lực của bạn. Xin hãy giúp tôi ở đây.
Nó làm việc cho tôi ... :) –
Nó làm việc cho tôi quá .. thanx !! :) –
Làm việc cho tôi cảm ơn rất nhiều. Tôi đã làm việc với nhiều phiên bản của Cordova đã cho tôi vấn đề này cho cùng một plugin. – satheeshwaran