diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..cd94850 --- /dev/null +++ b/.clang-format @@ -0,0 +1,13 @@ +--- +Language: Cpp +BasedOnStyle: LLVM + +ColumnLimit: 300 +IndentWidth: 4 +--- +Language: ObjC +BasedOnStyle: LLVM + +ColumnLimit: 300 +IndentWidth: 4 +... diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..3f73521 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "mitaki28.vscode-clang" + ] +} \ No newline at end of file diff --git a/src/ios/CountlyCordova.m b/src/ios/CountlyCordova.m index 6f8bb4e..7e7249e 100644 --- a/src/ios/CountlyCordova.m +++ b/src/ios/CountlyCordova.m @@ -1,14 +1,14 @@ /********* Countly.h Countly Plugin Implementation *******/ -#import "Countly.h" #import "CountlyCordova.h" +#import "Countly.h" #import "CountlyConfig.h" //#import "CountlyPushNotifications.h" #import //#import "CountlyCommon.h" #import "CountlyNative.h" -CountlyNative* countlyNative = nil; +CountlyNative *countlyNative = nil; //@interface CountlyPushNotifications() //- (void)sendToken; @@ -16,74 +16,74 @@ //@end @implementation CountlyCordova -- (void)init:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)init:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"init" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"init" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)isInitialized:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)isInitialized:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"isInitialized" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"isInitialized" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)recordEvent:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)recordEvent:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"recordEvent" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"recordEvent" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)recordView:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)recordView:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"recordView" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"recordView" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)setLoggingEnabled:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)setLoggingEnabled:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"setLoggingEnabled" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"setLoggingEnabled" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)setuserdata:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)setuserdata:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"setuserdata" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"setuserdata" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } // - (void)getDeviceID:(CDVInvokedUrlCommand*)command @@ -98,7 +98,6 @@ - (void)setuserdata:(CDVInvokedUrlCommand*)command // }]; // } - // - (void)sendRating:(CDVInvokedUrlCommand*)command // { // if(countlyNative == nil){ @@ -111,53 +110,51 @@ - (void)setuserdata:(CDVInvokedUrlCommand*)command // }]; // } -- (void)start:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)start:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"start" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"start" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } - -- (void)stop:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (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]; - }]; + [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){ +- (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]; - }]; + [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){ +- (void)update:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"update" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"update" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } // - (void)manualSessionHandling:(CDVInvokedUrlCommand*)command @@ -172,7 +169,6 @@ - (void)update:(CDVInvokedUrlCommand*)command // }]; // } - // - (void)updateSessionPeriod:(CDVInvokedUrlCommand*)command // { // if(countlyNative == nil){ @@ -209,671 +205,669 @@ - (void)update:(CDVInvokedUrlCommand*)command // }]; // } -- (void)getCurrentDeviceId:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)getCurrentDeviceId:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"getCurrentDeviceId" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"getCurrentDeviceId" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)getDeviceIdAuthor:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)getDeviceIdAuthor:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"getDeviceIdAuthor" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"getDeviceIdAuthor" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)changeDeviceId:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)changeDeviceId:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"changeDeviceId" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"changeDeviceId" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)setHttpPostForced:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)setHttpPostForced:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"setHttpPostForced" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"setHttpPostForced" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)enableParameterTamperingProtection:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)enableParameterTamperingProtection:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"enableParameterTamperingProtection" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"enableParameterTamperingProtection" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)startEvent:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)startEvent:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"startEvent" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"startEvent" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)cancelEvent:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)cancelEvent:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"cancelEvent" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"cancelEvent" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)endEvent:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)endEvent:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"endEvent" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"endEvent" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)setLocationInit:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)setLocationInit:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"setLocationInit" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"setLocationInit" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)setLocation:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)setLocation:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"setLocation" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"setLocation" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)enableCrashReporting:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)enableCrashReporting:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"enableCrashReporting" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"enableCrashReporting" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)addCrashLog:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)addCrashLog:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"addCrashLog" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"addCrashLog" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)logException:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)logException:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"logException" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"logException" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)sendPushToken:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)sendPushToken:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"sendPushToken" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"sendPushToken" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)askForNotificationPermission:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)askForNotificationPermission:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"askForNotificationPermission" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"askForNotificationPermission" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)registerForNotification:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)registerForNotification:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"registerForNotification" commandString: command.arguments callback: ^(NSString * theResult) - { - - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [pluginResult setKeepCallbackAsBool:YES]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"registerForNotification" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [pluginResult setKeepCallbackAsBool:YES]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)pushTokenType:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)pushTokenType:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"pushTokenType" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"pushTokenType" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)userData_setProperty:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)userData_setProperty:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"userData_setProperty" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"userData_setProperty" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)userData_increment:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)userData_increment:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"userData_increment" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"userData_increment" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)userData_incrementBy:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)userData_incrementBy:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"userData_incrementBy" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"userData_incrementBy" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)userData_multiply:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)userData_multiply:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"userData_multiply" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"userData_multiply" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)userData_saveMax:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)userData_saveMax:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"userData_saveMax" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"userData_saveMax" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)userData_saveMin:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)userData_saveMin:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"userData_saveMin" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"userData_saveMin" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)userData_setOnce:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)userData_setOnce:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"userData_setOnce" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"userData_setOnce" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)userData_pushUniqueValue:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)userData_pushUniqueValue:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"userData_pushUniqueValue" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"userData_pushUniqueValue" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)userData_pushValue:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)userData_pushValue:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"userData_pushValue" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"userData_pushValue" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)userData_pullValue:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)userData_pullValue:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"userData_pullValue" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"userData_pullValue" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)setRequiresConsent:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)setRequiresConsent:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"setRequiresConsent" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"setRequiresConsent" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)giveConsentInit:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)giveConsentInit:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"giveConsentInit" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"giveConsentInit" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)giveConsent:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)giveConsent:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"giveConsent" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"giveConsent" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)removeConsent:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)removeConsent:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"removeConsent" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"removeConsent" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)giveAllConsent:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)giveAllConsent:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"giveAllConsent" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"giveAllConsent" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)removeAllConsent:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)removeAllConsent:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"removeAllConsent" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"removeAllConsent" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)setOptionalParametersForInitialization:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)setOptionalParametersForInitialization:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"setOptionalParametersForInitialization" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"setOptionalParametersForInitialization" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)setRemoteConfigAutomaticDownload:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)setRemoteConfigAutomaticDownload:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"setRemoteConfigAutomaticDownload" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"setRemoteConfigAutomaticDownload" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)remoteConfigUpdate:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)remoteConfigUpdate:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"remoteConfigUpdate" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"remoteConfigUpdate" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)updateRemoteConfigForKeysOnly:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)updateRemoteConfigForKeysOnly:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"updateRemoteConfigForKeysOnly" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"updateRemoteConfigForKeysOnly" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)updateRemoteConfigExceptKeys:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)updateRemoteConfigExceptKeys:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"updateRemoteConfigExceptKeys" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"updateRemoteConfigExceptKeys" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)remoteConfigClearValues:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)remoteConfigClearValues:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"remoteConfigClearValues" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"remoteConfigClearValues" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)getRemoteConfigValueForKey:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)getRemoteConfigValueForKey:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"getRemoteConfigValueForKey" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"getRemoteConfigValueForKey" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)askForFeedback:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)askForFeedback:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"askForFeedback" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"askForFeedback" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)setStarRatingDialogTexts:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)setStarRatingDialogTexts:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"setStarRatingDialogTexts" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"setStarRatingDialogTexts" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)askForStarRating:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)askForStarRating:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"askForStarRating" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"askForStarRating" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)getFeedbackWidgets:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)getFeedbackWidgets:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"getFeedbackWidgets" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"getFeedbackWidgets" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)presentFeedbackWidget:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)presentFeedbackWidget:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"presentFeedbackWidget" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"presentFeedbackWidget" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)replaceAllAppKeysInQueueWithCurrentAppKey:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)replaceAllAppKeysInQueueWithCurrentAppKey:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"replaceAllAppKeysInQueueWithCurrentAppKey" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"replaceAllAppKeysInQueueWithCurrentAppKey" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)removeDifferentAppKeysFromQueue:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)removeDifferentAppKeysFromQueue:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"removeDifferentAppKeysFromQueue" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"removeDifferentAppKeysFromQueue" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)enableAttribution:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)enableAttribution:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"enableAttribution" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"enableAttribution" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)recordAttributionID:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)recordAttributionID:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"recordAttributionID" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"recordAttributionID" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)startTrace:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)startTrace:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"startTrace" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"startTrace" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)cancelTrace:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)cancelTrace:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"cancelTrace" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"cancelTrace" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)clearAllTraces:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)clearAllTraces:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"clearAllTraces" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"clearAllTraces" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)endTrace:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)endTrace:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"endTrace" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"endTrace" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)recordNetworkTrace:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)recordNetworkTrace:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"recordNetworkTrace" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"recordNetworkTrace" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)enableApm:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)enableApm:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"enableApm" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"enableApm" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } -- (void)appLoadingFinished:(CDVInvokedUrlCommand*)command -{ - if(countlyNative == nil){ +- (void)appLoadingFinished:(CDVInvokedUrlCommand *)command { + if (countlyNative == nil) { countlyNative = CountlyNative.new; } - [countlyNative onCall: @"appLoadingFinished" commandString: command.arguments callback: ^(NSString * theResult) - { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; + [countlyNative onCall:@"appLoadingFinished" + commandString:command.arguments + callback:^(NSString *theResult) { + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:theResult]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; } - @end diff --git a/src/ios/CountlyNative.m b/src/ios/CountlyNative.m index 983d802..4937ecd 100644 --- a/src/ios/CountlyNative.m +++ b/src/ios/CountlyNative.m @@ -14,13 +14,13 @@ static char coldstartKey; Result notificationListener = nil; NSDictionary *lastStoredNotification = nil; -NSMutableArray *notificationIDs = nil; // alloc here -NSMutableArray* countlyFeatures = nil; +NSMutableArray *notificationIDs = nil; // alloc here +NSMutableArray *countlyFeatures = nil; Boolean isInitialized = false; NSString *const pushPluginApplicationDidBecomeActiveNotification = @"pushPluginApplicationDidBecomeActiveNotification"; -NSString* const kCountlyCordovaSDKVersion = @"21.11.0"; -NSString* const kCountlyCordovaSDKName = @"js-cordovab-ios"; +NSString *const kCountlyCordovaSDKVersion = @"21.11.0"; +NSString *const kCountlyCordovaSDKName = @"js-cordovab-ios"; @interface CountlyFeedbackWidget () + (CountlyFeedbackWidget *)createWithDictionary:(NSDictionary *)dictionary; @@ -33,80 +33,62 @@ - (void)setSDKVersion:(NSString *)SDKVersion; @end @implementation AppDelegate (notification) -- (NSMutableArray *)launchNotification -{ +- (NSMutableArray *)launchNotification { return objc_getAssociatedObject(self, &launchNotificationKey); } -- (void)setLaunchNotification:(NSDictionary *)aDictionary -{ +- (void)setLaunchNotification:(NSDictionary *)aDictionary { objc_setAssociatedObject(self, &launchNotificationKey, aDictionary, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } -- (NSNumber *)coldstart -{ +- (NSNumber *)coldstart { return objc_getAssociatedObject(self, &coldstartKey); } -- (void)setColdstart:(NSNumber *)aNumber -{ +- (void)setColdstart:(NSNumber *)aNumber { objc_setAssociatedObject(self, &coldstartKey, aNumber, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } -- (void)dealloc -{ +- (void)dealloc { self.launchNotification = nil; // clear the association and release the object self.coldstart = nil; } -- (id) getCommandInstance:(NSString*)className -{ +- (id)getCommandInstance:(NSString *)className { return [self.viewController getCommandInstance:className]; } // its dangerous to override a method from within a category. // Instead we will use method swizzling. we set this up in the load call. -+ (void)load -{ ++ (void)load { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - + #ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS - Class class = [self class]; - SEL originalSelector = @selector(init); - SEL swizzledSelector = @selector(pushPluginSwizzledInit); - - Method original = class_getInstanceMethod(class, originalSelector); - Method swizzled = class_getInstanceMethod(class, swizzledSelector); - - BOOL didAddMethod = - class_addMethod(class, - originalSelector, - method_getImplementation(swizzled), - method_getTypeEncoding(swizzled)); - - if (didAddMethod) { - class_replaceMethod(class, - swizzledSelector, - method_getImplementation(original), - method_getTypeEncoding(original)); - } else { - method_exchangeImplementations(original, swizzled); - } + Class class = [self class]; + SEL originalSelector = @selector(init); + SEL swizzledSelector = @selector(pushPluginSwizzledInit); + + Method original = class_getInstanceMethod(class, originalSelector); + Method swizzled = class_getInstanceMethod(class, swizzledSelector); + + BOOL didAddMethod = class_addMethod(class, originalSelector, method_getImplementation(swizzled), method_getTypeEncoding(swizzled)); + + if (didAddMethod) { + class_replaceMethod(class, swizzledSelector, method_getImplementation(original), method_getTypeEncoding(original)); + } else { + method_exchangeImplementations(original, swizzled); + } #endif }); } #ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS -- (AppDelegate *)pushPluginSwizzledInit -{ +- (AppDelegate *)pushPluginSwizzledInit { UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self; - [[NSNotificationCenter defaultCenter]addObserver:self - selector:@selector(pushPluginOnApplicationDidBecomeActive:) - name:UIApplicationDidBecomeActiveNotification - object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushPluginOnApplicationDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil]; // This actually calls the original init method over in AppDelegate. Equivilent to calling super // on an overrided method, this is not recursive, although it appears that way. neat huh? @@ -137,7 +119,7 @@ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(N completionHandler(UIBackgroundFetchResultNewData); } else { COUNTLY_CORDOVA_LOG(@"just put it in the shade"); - //save it for later + // save it for later self.launchNotification = userInfo; completionHandler(UIBackgroundFetchResultNewData); } @@ -146,56 +128,46 @@ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(N completionHandler(UIBackgroundFetchResultNoData); } } -- (void)userNotificationCenter:(UNUserNotificationCenter *)center - willPresentNotification:(UNNotification *)notification - withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler -{ - COUNTLY_CORDOVA_LOG( @"NotificationCenter Handle push from foreground" ); +- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler { + COUNTLY_CORDOVA_LOG(@"NotificationCenter Handle push from foreground"); // custom code to handle push while app is in the foreground - [CountlyNative onNotification: notification.request.content.userInfo]; + [CountlyNative onNotification:notification.request.content.userInfo]; completionHandler(UNNotificationPresentationOptionNone); } -- (void)userNotificationCenter:(UNUserNotificationCenter *)center -didReceiveNotificationResponse:(UNNotificationResponse *)response - withCompletionHandler:(void(^)(void))completionHandler -{ - COUNTLY_CORDOVA_LOG(@"Push Plugin didReceiveNotificationResponse: actionIdentifier %@, notification: %@", response.actionIdentifier, - response.notification.request.content.userInfo); +- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler { + COUNTLY_CORDOVA_LOG(@"Push Plugin didReceiveNotificationResponse: actionIdentifier %@, notification: %@", response.actionIdentifier, response.notification.request.content.userInfo); NSMutableDictionary *userInfo = [response.notification.request.content.userInfo mutableCopy]; [userInfo setObject:response.actionIdentifier forKey:@"actionCallback"]; COUNTLY_CORDOVA_LOG(@"Push Plugin userInfo %@", userInfo); switch ([UIApplication sharedApplication].applicationState) { - case UIApplicationStateActive: - { - COUNTLY_CORDOVA_LOG(@"UIApplicationStateActive"); - [CountlyNative onNotification: response.notification.request.content.userInfo]; - if(notificationListener != nil){ - completionHandler(); - } - break; - } - case UIApplicationStateInactive: - { - COUNTLY_CORDOVA_LOG(@"UIApplicationStateInactive"); - self.launchNotification = response.notification.request.content.userInfo; - self.coldstart = [NSNumber numberWithBool:YES]; - break; + case UIApplicationStateActive: { + COUNTLY_CORDOVA_LOG(@"UIApplicationStateActive"); + [CountlyNative onNotification:response.notification.request.content.userInfo]; + if (notificationListener != nil) { + completionHandler(); } - case UIApplicationStateBackground: - { - COUNTLY_CORDOVA_LOG(@"UIApplicationStateBackground"); - void (^safeHandler)(void) = ^(void){ - dispatch_async(dispatch_get_main_queue(), ^{ - completionHandler(); - }); - }; - [CountlyNative onNotification: response.notification.request.content.userInfo]; - if(notificationListener != nil){ - completionHandler(); - } + break; + } + case UIApplicationStateInactive: { + COUNTLY_CORDOVA_LOG(@"UIApplicationStateInactive"); + self.launchNotification = response.notification.request.content.userInfo; + self.coldstart = [NSNumber numberWithBool:YES]; + break; + } + case UIApplicationStateBackground: { + COUNTLY_CORDOVA_LOG(@"UIApplicationStateBackground"); + void (^safeHandler)(void) = ^(void) { + dispatch_async(dispatch_get_main_queue(), ^{ + completionHandler(); + }); + }; + [CountlyNative onNotification:response.notification.request.content.userInfo]; + if (notificationListener != nil) { + completionHandler(); } } + } } - (void)pushPluginOnApplicationDidBecomeActive:(NSNotification *)notification { @@ -209,88 +181,79 @@ - (void)pushPluginOnApplicationDidBecomeActive:(NSNotification *)notification { [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]; } COUNTLY_CORDOVA_LOG(@"pushPluginOnApplicationDidBecomeActive: %@", self.launchNotification); - [CountlyNative onNotification: self.launchNotification]; + [CountlyNative onNotification:self.launchNotification]; [[NSNotificationCenter defaultCenter] postNotificationName:pushPluginApplicationDidBecomeActiveNotification object:nil]; } #endif @end - - -@interface CountlyNative () -{ +@interface CountlyNative () { } @end @implementation CountlyNative - CountlyConfig* config = nil; - Boolean isDebug = false; +CountlyConfig *config = nil; +Boolean isDebug = false; #ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS -+ (void)onNotification: (NSDictionary *) notificationMessage{ - if(!notificationMessage) { ++ (void)onNotification:(NSDictionary *)notificationMessage { + if (!notificationMessage) { COUNTLY_CORDOVA_LOG(@"onNotification, Notification received. No valid message"); return; } COUNTLY_CORDOVA_LOG(@"onNotification, Notification received. The notification %@", notificationMessage); - - NSDictionary* countlyPayload = notificationMessage[@"c"]; - if(!countlyPayload) { + + NSDictionary *countlyPayload = notificationMessage[@"c"]; + if (!countlyPayload) { COUNTLY_CORDOVA_LOG(@"onNotification, Notification received. Countly payload not found in notification dictionary!"); return; } NSString *notificationID = countlyPayload[@"i"]; - if(!notificationID) { + if (!notificationID) { COUNTLY_CORDOVA_LOG(@"onNotification, Notification received. Countly payload does not contains a valid notification ID!"); return; } - - if(notificationIDs == nil){ + + if (notificationIDs == nil) { notificationIDs = [[NSMutableArray alloc] init]; } [notificationIDs insertObject:notificationID atIndex:[notificationIDs count]]; - if(isInitialized){ - if(notificationListener != nil){ - notificationListener([NSString stringWithFormat:@"%@",notificationMessage]); + if (isInitialized) { + if (notificationListener != nil) { + notificationListener([NSString stringWithFormat:@"%@", notificationMessage]); } [CountlyNative recordPushAction]; - } - else{ + } else { // Notification is cached if SDK is not initialized and send in callback when 'registerForNotification' is call. lastStoredNotification = notificationMessage; } } -+ (void)recordPushAction -{ - for(int i=0,il = (int) notificationIDs.count;i 0) { - dispatch_async(dispatch_get_main_queue(), ^ { - isInitialized = true; - [[Countly sharedInstance] startWithConfig:config]; + dispatch_async(dispatch_get_main_queue(), ^{ + isInitialized = true; + [[Countly sharedInstance] startWithConfig:config]; #ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS - [CountlyNative recordPushAction]; + [CountlyNative recordPushAction]; #endif }); result(@"initialized."); } else { result(@"initialization failed!"); } - }else if ([@"isInitialized" isEqualToString:method]) { - dispatch_async(dispatch_get_main_queue(), ^ { - if(isInitialized){ - result(@"true"); - }else{ - result(@"false"); - } + } else if ([@"isInitialized" isEqualToString:method]) { + dispatch_async(dispatch_get_main_queue(), ^{ + if (isInitialized) { + result(@"true"); + } else { + result(@"false"); + } }); - }else if ([@"recordEvent" isEqualToString:method]) { - dispatch_async(dispatch_get_main_queue(), ^ { - NSString* key = [command objectAtIndex:0]; - NSString* countString = [command objectAtIndex:1]; - int count = [countString intValue]; - NSString* sumString = [command objectAtIndex:2]; - float sum = [sumString floatValue]; - NSString* durationString = [command objectAtIndex:3]; - int duration = [durationString intValue]; - NSMutableDictionary *segmentation = [[NSMutableDictionary alloc] init]; - - if((int)command.count > 4){ - for(int i=4,il=(int)command.count;i 4) { + for (int i = 4, il = (int)command.count; i < il; i += 2) { + segmentation[[command objectAtIndex:i]] = [command objectAtIndex:i + 1]; + } + } + [[Countly sharedInstance] recordEvent:key segmentation:segmentation count:count sum:sum duration:duration]; + NSString *resultString = @"recordEvent for: "; + resultString = [resultString stringByAppendingString:key]; + result(resultString); }); - }else if ([@"recordView" isEqualToString:method]) { - dispatch_async(dispatch_get_main_queue(), ^ { - NSString* recordView = [command objectAtIndex:0]; - NSMutableDictionary *segments = [[NSMutableDictionary alloc] init]; - int il=(int)command.count; - if(il > 2) { - for(int i=1;i 2) { + for (int i = 1; i < il; i += 2) { + @try { + segments[[command objectAtIndex:i]] = [command objectAtIndex:i + 1]; + } @catch (NSException *exception) { + COUNTLY_CORDOVA_LOG(@"recordView: Exception occured while parsing segments: %@", exception); + } + } + } + [Countly.sharedInstance recordView:recordView segmentation:segments]; + result(@"recordView Sent!"); }); - }else if ([@"setLoggingEnabled" isEqualToString:method]) { - dispatch_async(dispatch_get_main_queue(), ^ { - NSString* loggingEnable = [command objectAtIndex:0]; - if([@"true" isEqualToString:loggingEnable]){ - isDebug = true; - config.enableDebug = YES; - }else{ - isDebug = false; - config.enableDebug = NO; - } - result(@"setLoggingEnabled!"); + } else if ([@"setLoggingEnabled" isEqualToString:method]) { + dispatch_async(dispatch_get_main_queue(), ^{ + NSString *loggingEnable = [command objectAtIndex:0]; + if ([@"true" isEqualToString:loggingEnable]) { + isDebug = true; + config.enableDebug = YES; + } else { + isDebug = false; + config.enableDebug = NO; + } + result(@"setLoggingEnabled!"); }); - }else if ([@"setuserdata" isEqualToString:method]) { - dispatch_async(dispatch_get_main_queue(), ^ { - NSDictionary* userData = [command objectAtIndex:0]; - NSString* name = [userData objectForKey:@"name"]; - NSString* username = [userData objectForKey:@"username"]; - NSString* email = [userData objectForKey:@"email"]; - NSString* organization = [userData objectForKey:@"organization"]; - NSString* phone = [userData objectForKey:@"phone"]; - NSString* picture = [userData objectForKey:@"picture"]; - NSString* pictureLocalPath = [userData objectForKey:@"pictureLocalPath"]; - NSString* gender = [userData objectForKey:@"gender"]; - NSString* byear = [userData objectForKey:@"byear"]; - - if(name) { - Countly.user.name = name; - } - if(username) { - Countly.user.username = username; - } - if(email) { - Countly.user.email = email; - } - if(organization) { - Countly.user.organization = organization; - } - if(phone) { - Countly.user.phone = phone; - } - if(picture) { - Countly.user.pictureURL = picture; - } - if(pictureLocalPath) { - Countly.user.pictureLocalPath = pictureLocalPath; - } - if(gender) { - Countly.user.gender = gender; - } - if(byear) { - Countly.user.birthYear = @([byear integerValue]); - } - [Countly.user save]; + } else if ([@"setuserdata" isEqualToString:method]) { + dispatch_async(dispatch_get_main_queue(), ^{ + NSDictionary *userData = [command objectAtIndex:0]; + NSString *name = [userData objectForKey:@"name"]; + NSString *username = [userData objectForKey:@"username"]; + NSString *email = [userData objectForKey:@"email"]; + NSString *organization = [userData objectForKey:@"organization"]; + NSString *phone = [userData objectForKey:@"phone"]; + NSString *picture = [userData objectForKey:@"picture"]; + NSString *pictureLocalPath = [userData objectForKey:@"pictureLocalPath"]; + NSString *gender = [userData objectForKey:@"gender"]; + NSString *byear = [userData objectForKey:@"byear"]; + + if (name) { + Countly.user.name = name; + } + if (username) { + Countly.user.username = username; + } + if (email) { + Countly.user.email = email; + } + if (organization) { + Countly.user.organization = organization; + } + if (phone) { + Countly.user.phone = phone; + } + if (picture) { + Countly.user.pictureURL = picture; + } + if (pictureLocalPath) { + Countly.user.pictureLocalPath = pictureLocalPath; + } + if (gender) { + Countly.user.gender = gender; + } + if (byear) { + Countly.user.birthYear = @([byear integerValue]); + } + [Countly.user save]; }); - }else if ([@"getDeviceID" isEqualToString:method]) { - dispatch_async(dispatch_get_main_queue(), ^ { - NSString* deviceID = Countly.sharedInstance.deviceID; - result([NSString stringWithFormat:@"%@", deviceID]); + } else if ([@"getDeviceID" isEqualToString:method]) { + dispatch_async(dispatch_get_main_queue(), ^{ + NSString *deviceID = Countly.sharedInstance.deviceID; + result([NSString stringWithFormat:@"%@", deviceID]); }); - }else if ([@"start" isEqualToString:method]) { - dispatch_async(dispatch_get_main_queue(), ^ { - [Countly.sharedInstance beginSession]; - result(@"start!"); + } else if ([@"start" isEqualToString:method]) { + dispatch_async(dispatch_get_main_queue(), ^{ + [Countly.sharedInstance beginSession]; + result(@"start!"); }); - }else if ([@"stop" isEqualToString:method]) { - dispatch_async(dispatch_get_main_queue(), ^ { - [Countly.sharedInstance endSession]; - result(@"stop!"); + } else if ([@"stop" isEqualToString:method]) { + dispatch_async(dispatch_get_main_queue(), ^{ + [Countly.sharedInstance endSession]; + result(@"stop!"); }); - }else if ([@"halt" isEqualToString:method]) { // This method is not implemented in iOS SDK + } 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]) { - dispatch_async(dispatch_get_main_queue(), ^ { - [Countly.sharedInstance updateSession]; - result(@"update!"); + } else if ([@"update" isEqualToString:method]) { + dispatch_async(dispatch_get_main_queue(), ^{ + [Countly.sharedInstance updateSession]; + result(@"update!"); }); - }else if ([@"getCurrentDeviceId" isEqualToString:method]) { - dispatch_async(dispatch_get_main_queue(), ^ { - NSString* value = [Countly.sharedInstance deviceID]; - if(value){ - result(value); - } - else{ - NSString *value = @"deviceIdNotFound"; - result(value); - } + } else if ([@"getCurrentDeviceId" isEqualToString:method]) { + dispatch_async(dispatch_get_main_queue(), ^{ + NSString *value = [Countly.sharedInstance deviceID]; + if (value) { + result(value); + } else { + NSString *value = @"deviceIdNotFound"; + result(value); + } }); - } - else if ([@"getDeviceIdAuthor" isEqualToString:method]) { - dispatch_async(dispatch_get_main_queue(), ^ { - id value = [Countly.sharedInstance deviceIDType]; - if(value){ - result(@[value]); - } - else{ - NSString *value = @"deviceIDAuthorNotFound"; - result(@[value]); - } + } else if ([@"getDeviceIdAuthor" isEqualToString:method]) { + dispatch_async(dispatch_get_main_queue(), ^{ + id value = [Countly.sharedInstance deviceIDType]; + if (value) { + result(@[ value ]); + } else { + NSString *value = @"deviceIDAuthorNotFound"; + result(@[ value ]); + } }); - }else if ([@"changeDeviceId" isEqualToString:method]) { - dispatch_async(dispatch_get_main_queue(), ^ { - NSString* newDeviceID = [command objectAtIndex:0]; - NSString* onServerString = [command objectAtIndex:1]; - - if ([onServerString isEqual: @"1"]) { - [Countly.sharedInstance setNewDeviceID:newDeviceID onServer: YES]; - }else{ - [Countly.sharedInstance setNewDeviceID:newDeviceID onServer: NO]; - } + } else if ([@"changeDeviceId" isEqualToString:method]) { + dispatch_async(dispatch_get_main_queue(), ^{ + NSString *newDeviceID = [command objectAtIndex:0]; + NSString *onServerString = [command objectAtIndex:1]; + + if ([onServerString isEqual:@"1"]) { + [Countly.sharedInstance setNewDeviceID:newDeviceID onServer:YES]; + } else { + [Countly.sharedInstance setNewDeviceID:newDeviceID onServer:NO]; + } - result(@"changeDeviceId!"); + result(@"changeDeviceId!"); }); - }else if ([@"setHttpPostForced" isEqualToString:method]) { - dispatch_async(dispatch_get_main_queue(), ^ { - NSString* isEnabled = [command objectAtIndex:0]; - if ([isEnabled isEqual: @"1"]) { - config.alwaysUsePOST = YES; - }else{ - config.alwaysUsePOST = NO; - } + } else if ([@"setHttpPostForced" isEqualToString:method]) { + dispatch_async(dispatch_get_main_queue(), ^{ + NSString *isEnabled = [command objectAtIndex:0]; + if ([isEnabled isEqual:@"1"]) { + config.alwaysUsePOST = YES; + } else { + config.alwaysUsePOST = NO; + } - // config.alwaysUsePOST = YES; - result(@"setHttpPostForced!"); + // config.alwaysUsePOST = YES; + result(@"setHttpPostForced!"); }); - }else if ([@"enableParameterTamperingProtection" isEqualToString:method]) { - dispatch_async(dispatch_get_main_queue(), ^ { - NSString* salt = [command objectAtIndex:0]; - config.secretSalt = salt; - result(@"enableParameterTamperingProtection!"); + } else if ([@"enableParameterTamperingProtection" isEqualToString:method]) { + dispatch_async(dispatch_get_main_queue(), ^{ + NSString *salt = [command objectAtIndex:0]; + config.secretSalt = salt; + result(@"enableParameterTamperingProtection!"); }); - }else if ([@"startEvent" isEqualToString:method]) { - dispatch_async(dispatch_get_main_queue(), ^ { - NSString* eventName = [command objectAtIndex:0]; - [Countly.sharedInstance startEvent:eventName]; - result(@"startEvent!"); + } else if ([@"startEvent" isEqualToString:method]) { + dispatch_async(dispatch_get_main_queue(), ^{ + NSString *eventName = [command objectAtIndex:0]; + [Countly.sharedInstance startEvent:eventName]; + result(@"startEvent!"); }); - }else if ([@"cancelEvent" isEqualToString:method]) { - dispatch_async(dispatch_get_main_queue(), ^ { - NSString* eventName = [command objectAtIndex:0]; - [Countly.sharedInstance cancelEvent:eventName]; - result(@"cancelEvent!"); + } else if ([@"cancelEvent" isEqualToString:method]) { + dispatch_async(dispatch_get_main_queue(), ^{ + NSString *eventName = [command objectAtIndex:0]; + [Countly.sharedInstance cancelEvent:eventName]; + result(@"cancelEvent!"); }); - }else if ([@"endEvent" isEqualToString:method]) { + } else if ([@"endEvent" isEqualToString:method]) { - dispatch_async(dispatch_get_main_queue(), ^ { - NSString* key = [command objectAtIndex:0]; - NSString* countString = [command objectAtIndex:1]; - int count = [countString intValue]; - NSString* sumString = [command objectAtIndex:2]; - float sum = [sumString floatValue]; - NSMutableDictionary *segmentation = [[NSMutableDictionary alloc] init]; + dispatch_async(dispatch_get_main_queue(), ^{ + NSString *key = [command objectAtIndex:0]; + NSString *countString = [command objectAtIndex:1]; + int count = [countString intValue]; + NSString *sumString = [command objectAtIndex:2]; + float sum = [sumString floatValue]; + NSMutableDictionary *segmentation = [[NSMutableDictionary alloc] init]; - if((int)command.count > 3){ - for(int i=3,il=(int)command.count;i 3) { + for (int i = 3, il = (int)command.count; i < il; i += 2) { + segmentation[[command objectAtIndex:i]] = [command objectAtIndex:i + 1]; + } + } + [[Countly sharedInstance] endEvent:key segmentation:segmentation count:count sum:sum]; + NSString *resultString = @"endEvent for: "; + resultString = [resultString stringByAppendingString:key]; + result(resultString); }); - }else if ([@"setLocationInit" isEqualToString:method]) { - dispatch_async(dispatch_get_main_queue(), ^ { - NSString* countryCode = [command objectAtIndex:0]; - NSString* city = [command objectAtIndex:1]; - NSString* locationString = [command objectAtIndex:2]; - NSString* ipAddress = [command objectAtIndex:3]; - - if(locationString != nil && ![locationString isEqualToString:@"null"] && [locationString containsString:@","]){ - @try{ - NSArray *locationArray = [locationString componentsSeparatedByString:@","]; - NSString* latitudeString = [locationArray objectAtIndex:0]; - NSString* longitudeString = [locationArray objectAtIndex:1]; - - double latitudeDouble = [latitudeString doubleValue]; - double longitudeDouble = [longitudeString doubleValue]; - config.location = (CLLocationCoordinate2D){latitudeDouble,longitudeDouble}; + } else if ([@"setLocationInit" isEqualToString:method]) { + dispatch_async(dispatch_get_main_queue(), ^{ + NSString *countryCode = [command objectAtIndex:0]; + NSString *city = [command objectAtIndex:1]; + NSString *locationString = [command objectAtIndex:2]; + NSString *ipAddress = [command objectAtIndex:3]; + + if (locationString != nil && ![locationString isEqualToString:@"null"] && [locationString containsString:@","]) { + @try { + NSArray *locationArray = [locationString componentsSeparatedByString:@","]; + NSString *latitudeString = [locationArray objectAtIndex:0]; + NSString *longitudeString = [locationArray objectAtIndex:1]; + + double latitudeDouble = [latitudeString doubleValue]; + double longitudeDouble = [longitudeString doubleValue]; + config.location = (CLLocationCoordinate2D){latitudeDouble, longitudeDouble}; + } @catch (NSException *exception) { + COUNTLY_CORDOVA_LOG(@"Invalid location: %@", locationString); + } } - @catch(NSException *exception){ - COUNTLY_CORDOVA_LOG(@"Invalid location: %@", locationString); + if (city != nil && ![city isEqualToString:@"null"]) { + config.city = city; } - } - if(city != nil && ![city isEqualToString:@"null"]) { - config.city = city; - } - if(countryCode != nil && ![countryCode isEqualToString:@"null"]) { - config.ISOCountryCode = countryCode; - } - if(ipAddress != nil && ![ipAddress isEqualToString:@"null"]) { - config.IP = ipAddress; - } - result(@"setLocationInit!"); + if (countryCode != nil && ![countryCode isEqualToString:@"null"]) { + config.ISOCountryCode = countryCode; + } + if (ipAddress != nil && ![ipAddress isEqualToString:@"null"]) { + config.IP = ipAddress; + } + result(@"setLocationInit!"); }); - }else if ([@"setLocation" isEqualToString:method]) { - dispatch_async(dispatch_get_main_queue(), ^ { - NSString* countryCode = [command objectAtIndex:0]; - NSString* city = [command objectAtIndex:1]; - NSString* gpsCoordinate = [command objectAtIndex:2]; - NSString* ipAddress = [command objectAtIndex:3]; + } else if ([@"setLocation" isEqualToString:method]) { + dispatch_async(dispatch_get_main_queue(), ^{ + NSString *countryCode = [command objectAtIndex:0]; + NSString *city = [command objectAtIndex:1]; + NSString *gpsCoordinate = [command objectAtIndex:2]; + NSString *ipAddress = [command objectAtIndex:3]; - if([@"null" isEqualToString:city]){ - city = nil; - } - if([@"null" isEqualToString:countryCode]){ - countryCode = nil; - } - if([@"null" isEqualToString:gpsCoordinate]){ - gpsCoordinate = nil; - } - if([@"null" isEqualToString:ipAddress]){ - ipAddress = nil; - } + if ([@"null" isEqualToString:city]) { + city = nil; + } + if ([@"null" isEqualToString:countryCode]) { + countryCode = nil; + } + if ([@"null" isEqualToString:gpsCoordinate]) { + gpsCoordinate = nil; + } + if ([@"null" isEqualToString:ipAddress]) { + ipAddress = nil; + } + + CLLocationCoordinate2D locationCoordinate = [self getCoordinate:gpsCoordinate]; + [Countly.sharedInstance recordLocation:locationCoordinate city:city ISOCountryCode:countryCode IP:ipAddress]; - CLLocationCoordinate2D locationCoordinate = [self getCoordinate:gpsCoordinate]; - [Countly.sharedInstance recordLocation:locationCoordinate city:city ISOCountryCode:countryCode IP:ipAddress]; - - result(@"setLocation!"); + result(@"setLocation!"); }); - }else if ([@"enableCrashReporting" isEqualToString:method]) { + } else if ([@"enableCrashReporting" isEqualToString:method]) { [self addCountlyFeature:CLYCrashReporting]; result(@"enableCrashReporting!"); - }else if ([@"addCrashLog" isEqualToString:method]) { - dispatch_async(dispatch_get_main_queue(), ^ { - NSString* record = [command objectAtIndex:0]; - [Countly.sharedInstance recordCrashLog: record]; - result(@"addCrashLog!"); + } else if ([@"addCrashLog" isEqualToString:method]) { + dispatch_async(dispatch_get_main_queue(), ^{ + NSString *record = [command objectAtIndex:0]; + [Countly.sharedInstance recordCrashLog:record]; + result(@"addCrashLog!"); }); - }else if ([@"logException" isEqualToString:method]) { - dispatch_async(dispatch_get_main_queue(), ^ { - NSString* execption = [command objectAtIndex:0]; - NSString* nonfatal = [command objectAtIndex:1]; - NSArray *nsException = [execption componentsSeparatedByString:@"\n"]; + } else if ([@"logException" isEqualToString:method]) { + dispatch_async(dispatch_get_main_queue(), ^{ + NSString *execption = [command objectAtIndex:0]; + NSString *nonfatal = [command objectAtIndex:1]; + NSArray *nsException = [execption componentsSeparatedByString:@"\n"]; - NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; - for(int i=2,il=(int)command.count;i * _Nonnull feedbackWidgets, NSError * _Nonnull error) { - NSMutableArray* feedbackWidgetsArray = [NSMutableArray arrayWithCapacity:feedbackWidgets.count]; - for (CountlyFeedbackWidget* retrievedWidget in feedbackWidgets) { - NSMutableDictionary* feedbackWidget = [NSMutableDictionary dictionaryWithCapacity:3]; - feedbackWidget[@"id"] = retrievedWidget.ID; - feedbackWidget[@"type"] = retrievedWidget.type; - feedbackWidget[@"name"] = retrievedWidget.name; - [feedbackWidgetsArray addObject:feedbackWidget]; - } - result(feedbackWidgetsArray); - }]; + } else if ([@"getFeedbackWidgets" isEqualToString:method]) { + dispatch_async(dispatch_get_main_queue(), ^{ + [Countly.sharedInstance getFeedbackWidgets:^(NSArray *_Nonnull feedbackWidgets, NSError *_Nonnull error) { + NSMutableArray *feedbackWidgetsArray = [NSMutableArray arrayWithCapacity:feedbackWidgets.count]; + for (CountlyFeedbackWidget *retrievedWidget in feedbackWidgets) { + NSMutableDictionary *feedbackWidget = [NSMutableDictionary dictionaryWithCapacity:3]; + feedbackWidget[@"id"] = retrievedWidget.ID; + feedbackWidget[@"type"] = retrievedWidget.type; + feedbackWidget[@"name"] = retrievedWidget.name; + [feedbackWidgetsArray addObject:feedbackWidget]; + } + result(feedbackWidgetsArray); + }]; }); - }else if ([@"presentFeedbackWidget" isEqualToString:method]) { - dispatch_async(dispatch_get_main_queue(), ^ { - NSString* widgetId = [command objectAtIndex:0]; - NSString* widgetType = [command objectAtIndex:1]; - NSMutableDictionary* feedbackWidgetsDict = [NSMutableDictionary dictionaryWithCapacity:3]; - - feedbackWidgetsDict[@"_id"] = widgetId; - feedbackWidgetsDict[@"type"] = widgetType; - feedbackWidgetsDict[@"name"] = widgetType; - CountlyFeedbackWidget *feedback = [CountlyFeedbackWidget createWithDictionary:feedbackWidgetsDict]; - [feedback present]; + } else if ([@"presentFeedbackWidget" isEqualToString:method]) { + dispatch_async(dispatch_get_main_queue(), ^{ + NSString *widgetId = [command objectAtIndex:0]; + NSString *widgetType = [command objectAtIndex:1]; + NSMutableDictionary *feedbackWidgetsDict = [NSMutableDictionary dictionaryWithCapacity:3]; + + feedbackWidgetsDict[@"_id"] = widgetId; + feedbackWidgetsDict[@"type"] = widgetType; + feedbackWidgetsDict[@"name"] = widgetType; + CountlyFeedbackWidget *feedback = [CountlyFeedbackWidget createWithDictionary:feedbackWidgetsDict]; + [feedback present]; }); - }else if ([@"replaceAllAppKeysInQueueWithCurrentAppKey" isEqualToString:method]) { - dispatch_async(dispatch_get_main_queue(), ^ { - [Countly.sharedInstance replaceAllAppKeysInQueueWithCurrentAppKey]; + } else if ([@"replaceAllAppKeysInQueueWithCurrentAppKey" isEqualToString:method]) { + dispatch_async(dispatch_get_main_queue(), ^{ + [Countly.sharedInstance replaceAllAppKeysInQueueWithCurrentAppKey]; }); - }else if ([@"removeDifferentAppKeysFromQueue" isEqualToString:method]) { - dispatch_async(dispatch_get_main_queue(), ^ { - [Countly.sharedInstance removeDifferentAppKeysFromQueue]; + } else if ([@"removeDifferentAppKeysFromQueue" isEqualToString:method]) { + dispatch_async(dispatch_get_main_queue(), ^{ + [Countly.sharedInstance removeDifferentAppKeysFromQueue]; }); - }else if ([@"getPlatformVersion" isEqualToString:method]) { + } else if ([@"getPlatformVersion" isEqualToString:method]) { result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]); - }else if ([@"recordAttributionID" isEqualToString:method]) { - dispatch_async(dispatch_get_main_queue(), ^ { - NSString* attributionID = [command objectAtIndex:0]; - [Countly.sharedInstance recordAttributionID: attributionID]; + } else if ([@"recordAttributionID" isEqualToString:method]) { + dispatch_async(dispatch_get_main_queue(), ^{ + NSString *attributionID = [command objectAtIndex:0]; + [Countly.sharedInstance recordAttributionID:attributionID]; }); result(@"recordAttributionID!"); - }else if ([@"startTrace" isEqualToString:method]) { - dispatch_async(dispatch_get_main_queue(), ^ { - NSString* traceKey = [command objectAtIndex:0]; - [Countly.sharedInstance startCustomTrace: traceKey]; + } else if ([@"startTrace" isEqualToString:method]) { + dispatch_async(dispatch_get_main_queue(), ^{ + NSString *traceKey = [command objectAtIndex:0]; + [Countly.sharedInstance startCustomTrace:traceKey]; }); result(@"startTrace!"); - }else if ([@"cancelTrace" isEqualToString:method]) { - dispatch_async(dispatch_get_main_queue(), ^ { - NSString* traceKey = [command objectAtIndex:0]; - [Countly.sharedInstance cancelCustomTrace: traceKey]; + } else if ([@"cancelTrace" isEqualToString:method]) { + dispatch_async(dispatch_get_main_queue(), ^{ + NSString *traceKey = [command objectAtIndex:0]; + [Countly.sharedInstance cancelCustomTrace:traceKey]; }); result(@"cancelTrace!"); - }else if ([@"clearAllTraces" isEqualToString:method]) { - dispatch_async(dispatch_get_main_queue(), ^ { - [Countly.sharedInstance clearAllCustomTraces]; + } else if ([@"clearAllTraces" isEqualToString:method]) { + dispatch_async(dispatch_get_main_queue(), ^{ + [Countly.sharedInstance clearAllCustomTraces]; }); result(@"clearAllTraces!"); - }else if ([@"endTrace" isEqualToString:method]) { - dispatch_async(dispatch_get_main_queue(), ^ { - NSString* traceKey = [command objectAtIndex:0]; - NSMutableDictionary *metrics = [[NSMutableDictionary alloc] init]; - for(int i=1,il=(int)command.count;i 2) { + if (locationArray.count > 2) { COUNTLY_CORDOVA_LOG(@"Invalid location Coordinates:[%@], it should contains only two comma seperated values", gpsCoordinate); } - NSString* latitudeString = [locationArray objectAtIndex:0]; - NSString* longitudeString = [locationArray objectAtIndex:1]; - + NSString *latitudeString = [locationArray objectAtIndex:0]; + NSString *longitudeString = [locationArray objectAtIndex:1]; + double latitudeDouble = [latitudeString doubleValue]; double longitudeDouble = [longitudeString doubleValue]; - if(latitudeDouble == 0 || longitudeDouble == 0) { + if (latitudeDouble == 0 || longitudeDouble == 0) { COUNTLY_CORDOVA_LOG(@"Invalid location Coordinates, One of the values parsed to a 0, double check that given coordinates are correct:[%@]", gpsCoordinate); } - locationCoordinate = (CLLocationCoordinate2D){latitudeDouble,longitudeDouble}; - } - @catch(NSException *exception) { + locationCoordinate = (CLLocationCoordinate2D){latitudeDouble, longitudeDouble}; + } @catch (NSException *exception) { COUNTLY_CORDOVA_LOG(@"Invalid location Coordinates:[%@], Exception occurred while parsing Coordinates:[%@]", gpsCoordinate, exception); } - } - else { + } else { COUNTLY_CORDOVA_LOG(@"Invalid location Coordinates:[%@], lat and long values should be comma separated", gpsCoordinate); } - } return locationCoordinate; }