2017-01-19 5 views
0

私は、Bluetoothのゼブラプリンタ用のプラグインを作成しました。私はそれを動作させることができ、正常に印刷されますが、プリンタがオフになっているか接続されていない場合、エラーをアプリケーションに戻す必要があります。これをObjective Cのアラートで直接開くことができますが、実際にエラーをモバイルアプリに戻す必要があるため、エラーが発生した場合に新しい操作を作成できます。Objective CプラグインからIonic/Cordova Appに戻るにエラーが出ない

コードをコンパイルしてビルドしますが、コードを実行すると、エラーがJavaScriptエラー関数に返されません。私はObjective Cをあまりよく知らないので、これで自分のやり方を考えています。ここで

は(私は、この関数にコードのステップということを見ることができますが、返送されません)バックアプリに送られるべきであるObjective Cのコードである:ここで

__block CDVPluginResult* result; //Declared at the beginning of the print function in .m file 

dispatch_async(dispatch_get_main_queue(), ^{ 
      if(success != YES || error != nil) { 

result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR 
          messageAsString:[NSString stringWithFormat: 
          @"Either the printer is turned off or not connected "]]; 
      } 
     }); 

は私のjavascriptのです私はプリンタへの呼び出しを開始します。

$scope.printTicket = function() { 
$ionicPlatform.ready(function() { 

    cordova.plugins.zebra.printer.sendZplOverBluetooth($scope.printObj, function successCallback() { 
     console.log('SUCCESS: Print'); 

    }, function errorCallback() { 
     console.log('ERROR: Print'); 

    }); 

}) 
} 

大変助かります。あなたが実際にsendPluginResultでそれを作成した後、プラグインの結果を送信する必要が

答えて

1

- のようなもの:

- (void) yourPluginFunction: (CDVInvokedUrlCommand*)command 
{ 
    __block CDVPluginResult* result; //Declared at the beginning of the print function in .m file 

    dispatch_async(dispatch_get_main_queue(), ^{ 
     if(success != YES || error != nil) { 

      result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR 
       messageAsString:[NSString stringWithFormat: 
       @"Either the printer is turned off or not connected "]]; 

      [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; 
     } 
    }); 
} 
+0

は完璧勤務しました。あなたが投稿する前に私は実際にこれを見つけましたが、私はあなたに投票をお願いします。ありがとう。 –

関連する問題