Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
Halt method added for android and iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
trinisofttechnologies committed Mar 14, 2020
1 parent 9e30e8a commit 03c120b
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 24 deletions.
13 changes: 5 additions & 8 deletions Countly.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ Countly.start = function(){
Countly.stop = function(){
cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","stop",[]);
}
// countly halt for android
Countly.halt = function(){
cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","halt",[]);
}

// countly manualSessionHandling for android
// Countly.manualSessionHandling = function(){
Expand Down Expand Up @@ -177,17 +181,10 @@ Countly.logException = function(exception, nonfatal, segments){
cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","logException",args);
};

Countly.startSession = function(){
cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","startSession",[]);
}

Countly.endSession = function(){
cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","endSession",[]);
}

Countly.enableParameterTamperingProtection = function(salt){
cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","enableParameterTamperingProtection",[salt.toString() || ""]);
}

Countly.startEvent = function(key){
cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","startEvent",[key.toString() || ""]);
}
Expand Down
6 changes: 6 additions & 0 deletions src/android/CountlyCordova.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ else if("logException".equals(action)){
else if ("start".equals(action)) {
callbackContext.success(countlyNative.start(args));
}
else if ("stop".equals(action)) {
callbackContext.success(countlyNative.stop(args));
}
else if ("halt".equals(action)) {
callbackContext.success(countlyNative.halt(args));
}

else if ("askForNotificationPermission".equals(action)) {
callbackContext.success(countlyNative.askForNotificationPermission(args));
Expand Down
6 changes: 5 additions & 1 deletion src/android/CountlyNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,16 @@ public String start(JSONArray args){
return "started: success";
}


public String stop(JSONArray args){
Countly.sharedInstance().onStop();
return "stoped: success";
}

public String halt(JSONArray args){
Countly.sharedInstance().halt();
return "halt: success";
}



// public String eventSendThreshold(JSONArray args){
Expand Down
1 change: 1 addition & 0 deletions src/ios/CountlyCordova.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- (void)sendRating:(CDVInvokedUrlCommand*)command;
- (void)start:(CDVInvokedUrlCommand*)command;
- (void)update:(CDVInvokedUrlCommand*)command;
- (void)halt:(CDVInvokedUrlCommand*)command;
- (void)manualSessionHandling:(CDVInvokedUrlCommand*)command;
- (void)stop:(CDVInvokedUrlCommand*)command;
- (void)updateSessionPeriod:(CDVInvokedUrlCommand*)command;
Expand Down
36 changes: 25 additions & 11 deletions src/ios/CountlyCordova.m
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,31 @@ - (void)start:(CDVInvokedUrlCommand*)command
}];
}


- (void)stop:(CDVInvokedUrlCommand*)command
{
if(countlyNative == nil){
countlyNative = CountlyNative.new;
}
[countlyNative onCall: @"stop" commandString: command.arguments callback: ^(NSString * theResult)
{
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}


- (void)halt:(CDVInvokedUrlCommand*)command
{
if(countlyNative == nil){
countlyNative = CountlyNative.new;
}
[countlyNative onCall: @"halt" commandString: command.arguments callback: ^(NSString * theResult)
{
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}
- (void)update:(CDVInvokedUrlCommand*)command
{
if(countlyNative == nil){
Expand All @@ -135,17 +160,6 @@ - (void)update:(CDVInvokedUrlCommand*)command
// }];
// }

- (void)stop:(CDVInvokedUrlCommand*)command
{
if(countlyNative == nil){
countlyNative = CountlyNative.new;
}
[countlyNative onCall: @"stop" commandString: command.arguments callback: ^(NSString * theResult)
{
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}

// - (void)updateSessionPeriod:(CDVInvokedUrlCommand*)command
// {
Expand Down
10 changes: 6 additions & 4 deletions src/ios/CountlyNative.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ - (void) onCall:(NSString *)method commandString:(NSArray *)command callback:(Re
[Countly.sharedInstance beginSession];
result(@"start!");

}else if ([@"stop" isEqualToString:method]) {
[Countly.sharedInstance endSession];
result(@"stop!");
}else if ([@"halt" isEqualToString:method]) { // This method is not implemented in iOS SDK
// [Countly.sharedInstance endSession];
result(@"No implemntation for halt!");
}else if ([@"update" isEqualToString:method]) {
[Countly.sharedInstance updateSession];
result(@"update!");
Expand All @@ -136,10 +142,6 @@ - (void) onCall:(NSString *)method commandString:(NSArray *)command callback:(Re
// config.manualSessionHandling = YES;
// result(@"manualSessionHandling!");

}else if ([@"stop" isEqualToString:method]) {
[Countly.sharedInstance endSession];
result(@"stop!");

// }else if ([@"updateSessionPeriod" isEqualToString:method]) {
// config.updateSessionPeriod = [[command objectAtIndex:0] intValue];
// result(@"updateSessionPeriod!");
Expand Down

0 comments on commit 03c120b

Please sign in to comment.