FTP上传后没有获得成功回调

时间:2014-08-23 16:45:06

标签: ios cordova ibm-mobilefirst

我正在为ipad开发一个基于worklight的应用程序,我必须在使用CDVPlugin成功上传FTP文件后将响应发送到java脚本。最初我正在调用从java脚本调用ios到以下提及函数。

- (void)sendFile:(CDVInvokedUrlCommand*)command {
      ...
      ...
      callbackId = command.callbackId;
      self.callbackId = command.callbackId;
      NSLog(@"callback ID Top %@",callbackId);
}

任务完成后,我将使用以下代码将状态发送回javascript。

//完成后的最后一次通话:

- (void) returnSuccess {
      NSMutableDictionary* posError = [NSMutableDictionary dictionaryWithCapacity:2];
      [posError setObject: [NSNumber numberWithInt: CDVCommandStatus_OK] forKey:@"code"];
      [posError setObject: @"Success" forKey: @"message"];
      CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:posError];

       //[self.commandDelegate sendPluginResult:result callbackId:callbackId];
       [self.commandDelegate sendPluginResult:result callbackId:self.callbackId];
       NSLog(@"result ==>> %@",result);
       NSLog(@"callbackId down ==>> %@",callbackId);
}

但我的问题是我没有在javascript中收到任何内容。当我调试代码时,控件转到所有行,并且还打印所有nslog行(FtpUpload575396340)仍然没有响应发送到javascript。

可以请任何人帮忙,告诉我这可能有什么问题吗?

JAVASCRIPT CODE:

function upload(){
var args = {};
args.address = " ";
args.username = " ";
args.password = "  "; 
cordova.exec(successCallback, failCallback, "FtpUpload", "sendFile", [args]);  
}



function successCallback(data){
//busyInd.hide();
var dialogSuccessTitle = "Success";
var dialogSuccessText =data.message; 
WL.SimpleDialog.show(dialogSuccessTitle, dialogSuccessText, 
    [{ text:'OK' },{ text:'Cancel' }  ]); 
// $('#show_button').show();
document.getElementById("show_button").disabled=false;
console.log('successCallback' + JSON.stringify(data));


}



function failCallback(data){
//busyInd.hide();
var dialogErrorTitle = "Warning"; 
var dialogErrorText = data.message;  
WL.SimpleDialog.show(dialogErrorTitle, dialogErrorText, 
    [{ text:'OK' },{ text:'Cancel' } ]);
//$('#show_button').show();
document.getElementById("show_button").disabled=false;
console.log('failCallback' + JSON.stringify(data));
}

1 个答案:

答案 0 :(得分:2)

我没有获得成功回调,因为每次上传操作后我的“self.commandDelegate”都变为null。 所以我在这里解释我的方法 我添加了

CDVPlugin *handler;
@implementation FtpUpload
{
uint8_t                     _buffer[kSendBufferSize];
}

在顶部和第一种方法我喜欢那样

- (void)sendFile:(CDVInvokedUrlCommand*)command { 
callbackId = command.callbackId;
self.callbackId = command.callbackId; 
handler = self; 
}

然后回归成功

- (void) returnSuccess {

NSMutableDictionary* posError = [NSMutableDictionary dictionaryWithCapacity:2];
[posError setObject: [NSNumber numberWithInt: CDVCommandStatus_OK] forKey:@"code"];
[posError setObject: @"Success" forKey: @"message"];
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:posError];  
[handler.commandDelegate sendPluginResult:result callbackId:callbackId];


}

所以我的问题现在解决了。