2013-08-05 27 views
5

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

  1. 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']); 
        } 
    }; 
    
  2. 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 
    
  3. tôi thêm vào sau mã để config.xml file:

    <feature name="HelloPlugin"> 
        <param name="ios-package" value="CDVPlugin"/> 
    </feature> 
    
  4. Cuối cùng tôi sửa đổi index.html theo cách sau:

    1. Script tham khảo thêm.()
    2. 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); 
          } 
      
    3. 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.

Trả lời

7

Điều đầu tiên nhảy ra là tên gói plugin của bạn. Nó sẽ là tên lớp iOS của bạn là "HelloPlugin".

<param name="ios-package" value="HelloPlugin"/> 

Một trong những mục đích của cách tham chiếu mới là cho phép tính linh hoạt và khả năng tương thích ngược của tên plugin đặc biệt trên Android. Ví dụ:

<feature name="HelloPlugin"> 
    <param name="ios-package" value="HelloCDVPlugin"/> 
    <param name="android-package" value="com.phonegap.plugins.HelloCDVPlugin"/> 
</feature> 

đâu "HelloCDVPlugin" là tên lớp iOS của bạn và "com.phonegap.plugins.HelloCDVPlugin" là tên lớp Android của bạn.

+2

Nó làm việc cho tôi ... :) –

+0

Nó làm việc cho tôi quá .. thanx !! :) –

+0

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

1

Sử dụng dưới mã cho js

cordova.define("cordova/plugin/hello", 
function (require, exports, module) { 

var exec = require('cordova/exec'); 

function greet(name, win, fail) { 
    exec(win, fail, "Hello", 
     "greet", [name]); 
} 

module.exports = { 
    greet: greet 
} 
} 
); 

và thay đổi cordova.exec để

exec(this.callbacks.onSuccess, this.callbacks.onError, "Hello", "greet", [defaults]); 

Bạn có thể tìm thấy ví dụ từ bên dưới liên kết

https://github.com/cristobal/phonegap-ios-datepicker-plugin

Bạn phải thay đổi mã theo yêu cầu của bạn.

Các vấn đề liên quan