Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes to the android and iOS remote calls #6

Merged
merged 2 commits into from
Feb 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/android/CommunicationHelperPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/ios/BEMCommunicationHelperPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,6 +26,7 @@ - (void)pushGetJSON:(CDVInvokedUrlCommand *)command
resultWithStatus:CDVCommandStatus_OK
messageAsDictionary:parsedResult];
[self.commandDelegate sendPluginResult:result callbackId:callbackId];
}
}];
}
@catch (NSException *exception) {
Expand Down