jquery - Issue with deffered object and phonegap plugin when then call -


how can execute following

[self.commanddelegate sendpluginresult:[cdvpluginresult resultwithstatus:cdvcommandstatus_ok messageasstring:**response**] callbackid:command.callbackid ]; 

and result as

$.when(phonegap.function(params)).then(function (**resp**) { //get response here   }); 

you need use cordova.exec api make works

make sure define plugin in config.xml

<feature name="customplugin">       <param name="ios-package" value="customplugin" /> </feature> 

implementing plug-in using objective-c code

customplugin.h

#import <foundation/foundation.h> #import <cordova/cdv.h>  @interface customplugin : cdvplugin  - (void)sayhello:(cdvinvokedurlcommand*)command;  @end 

customplugin.m

#import "customplugin.h"      @implementation customplugin      - (void)sayhello:(cdvinvokedurlcommand*)command{          nsstring *responsestring =             [nsstring stringwithformat:@"hello world, %@", [command.arguments objectatindex:0]];          cdvpluginresult *pluginresult =             [cdvpluginresult resultwithstatus:cdvcommandstatus_ok messageasstring:responsestring];          [self.commanddelegate sendpluginresult:pluginresult callbackid:command.callbackid];     }      @end 

calling plug-in javascript

function initial(){     var name = $("#nameinput").val();     cordova.exec(sayhellosuccess, sayhellofailure, "customplugin", "sayhello", [name]); }  function sayhellosuccess(data){     alert("ok: " + data); }  function sayhellofailure(data){     alert("fail: " + data); } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -