Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, I figured this out by reading the basic examples in the <a href="http://docs.phonegap.com/en/2.0.0/guide_plugin-development_index.md.html" rel="nofollow">Cordova Plugin Development Guide</a> closely. The problem was with the ordering of parameters for <code>cordova.exec()</code>, which must have changed recently.</p> <p>I plan to submit a pull request on GitHub with a working version of the plugin, but for now, here's the basic solution. </p> <p>Before asking this question, I had updated the imports in AudioEncode.h from <code>#import &lt;PhoneGap/PGPlugin.h&gt;</code> to:</p> <pre><code>#import &lt;Cordova/CDVPlugin.h&gt; #import &lt;Cordova/CDVPluginResult.h&gt; </code></pre> <p>Any reference to <code>PGPlugin</code> should also be updated to <code>CDVPlugin</code>, and <code>PhoneGap</code> should become <code>cordova</code>.</p> <p>Here's the crux of the problem: in AudioEncode.js, <code>cordova.exec()</code> (where the original plugin calls <code>PhoneGap.exec()</code>) needs to be called like this:</p> <pre><code>AudioEncode.prototype.encodeAudio = function(audioPath, successCallback, failCallback) { cordova.exec(successCallback, failCallback, "AudioEncode", "encodeAudio", [audioPath]); }; </code></pre> <p>If you don't order the parameters like this, the callbacks won't be passed in (although audioPath was...). Look at the docs for more details, but the parameters have to be the two callbacks first, the module name, the module action, and finally an array of extra parameters.</p> <p>Then, you'll need to read in the parameters in the main encodeAudio function like this:</p> <pre><code>self.callback = [[arguments objectAtIndex:0] retain]; NSString* audioPath = [arguments objectAtIndex:1]; </code></pre> <p>Note that there is only one callback object now, which contains references to the success and fail callbacks. This means that whenever the plugin sets up variables for <code>successCallback</code> and <code>failCallback</code>, you now only need <code>callback</code> (e.g. <code>@synthesize callback</code>). This is also declared in the AudioEncode.h file with <code>@interface</code> and <code>@property</code>.</p> <p>Now, when actually firing the callbacks &amp; returning data (in the <code>doSuccessCallback</code> and <code>doFailCallback</code> functions), you need to use <code>CDVPluginResult</code>, like this:</p> <pre><code>CDVPluginResult* pluginResult = nil; NSString* javaScript = nil; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:path]; javaScript = [pluginResult toSuccessCallbackString:self.callback]; [self writeJavascript: javaScript]; [self.callback release]; </code></pre> <p>Until I get the updated module up on GitHub, this should help anyone to get the plugin working.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload