diff --git a/src/android/CommunicationHelperPlugin.java b/src/android/CommunicationHelperPlugin.java index 8496da6..3c67364 100644 --- a/src/android/CommunicationHelperPlugin.java +++ b/src/android/CommunicationHelperPlugin.java @@ -11,20 +11,28 @@ public class CommunicationHelperPlugin extends CordovaPlugin { @Override - public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException { + public boolean execute(String action, JSONArray data, final CallbackContext callbackContext) throws JSONException { if (action.equals("pushGetJSON")) { try { - Context ctxt = cordova.getActivity(); + final Context ctxt = cordova.getActivity(); String relativeURL = data.getString(0); - JSONObject filledMessage = data.getJSONObject(1); + final JSONObject filledMessage = data.getJSONObject(1); String commuteTrackerHost = ConnectionSettings.getConnectURL(ctxt); - String fullURL = commuteTrackerHost + relativeURL; + final String fullURL = commuteTrackerHost + relativeURL; + cordova.getThreadPool().execute(new Runnable() { + public void run() { + try { String resultString = CommunicationHelper.pushGetJSON(ctxt, fullURL, filledMessage); callbackContext.success(new JSONObject(resultString)); } catch (Exception e) { callbackContext.error("While pushing/getting from server "+e.getMessage()); + } + } + }); + } catch (Exception e) { + callbackContext.error("While pushing/getting from server "+e.getMessage()); } return true; } else { diff --git a/src/ios/BEMCommunicationHelperPlugin.m b/src/ios/BEMCommunicationHelperPlugin.m index 4089e03..5730488 100644 --- a/src/ios/BEMCommunicationHelperPlugin.m +++ b/src/ios/BEMCommunicationHelperPlugin.m @@ -14,7 +14,7 @@ - (void)pushGetJSON:(CDVInvokedUrlCommand *)command [CommunicationHelper pushGetJSON:filledMessage toURL:relativeURL completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { if (error != NULL) { [self sendError:error callBackID:callbackId]; - } + } else { NSError *parseError; NSDictionary *parsedResult = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions @@ -26,6 +26,7 @@ - (void)pushGetJSON:(CDVInvokedUrlCommand *)command resultWithStatus:CDVCommandStatus_OK messageAsDictionary:parsedResult]; [self.commandDelegate sendPluginResult:result callbackId:callbackId]; + } }]; } @catch (NSException *exception) {