From 2492b2cbbb3df843c2451b823d4a2c297d6f4000 Mon Sep 17 00:00:00 2001 From: Frank Schmitt Date: Thu, 18 Jan 2018 14:44:34 -0800 Subject: [PATCH] Autoformat --- src/ios/.clang-format | 71 +++++ src/ios/ApptentiveBridge.h | 5 +- src/ios/ApptentiveBridge.m | 620 +++++++++++++++++-------------------- 3 files changed, 366 insertions(+), 330 deletions(-) create mode 100644 src/ios/.clang-format mode change 100755 => 100644 src/ios/ApptentiveBridge.h mode change 100755 => 100644 src/ios/ApptentiveBridge.m diff --git a/src/ios/.clang-format b/src/ios/.clang-format new file mode 100644 index 0000000..6906938 --- /dev/null +++ b/src/ios/.clang-format @@ -0,0 +1,71 @@ +--- +Language: Cpp +# BasedOnStyle: Google +AccessModifierOffset: -1 +ConstructorInitializerIndentWidth: 4 + +AlignAfterOpenBracket: false +AlignEscapedNewlinesLeft: true +AlignOperands: false +AlignTrailingComments: true + +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: true +AllowShortIfStatementsOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AllowShortLoopsOnASingleLine: true + +AlwaysBreakAfterDefinitionReturnType: false +AlwaysBreakTemplateDeclarations: false +AlwaysBreakBeforeMultilineStrings: false + +BreakBeforeBinaryOperators: None +BreakBeforeTernaryOperators: false +BreakConstructorInitializersBeforeComma: false + +BinPackArguments: true +BinPackParameters: true +ColumnLimit: 0 +ConstructorInitializerAllOnOneLineOrOnePerLine: true +DerivePointerAlignment: false +ExperimentalAutoDetectBinPacking: false +IndentCaseLabels: true +IndentWrappedFunctionNames: false +IndentFunctionDeclarationAfterType: false +MaxEmptyLinesToKeep: 2 +KeepEmptyLinesAtTheStartOfBlocks: false +NamespaceIndentation: Inner +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true +PenaltyBreakBeforeFirstCallParameter: 10000 +PenaltyBreakComment: 300 +PenaltyBreakString: 10000 +PenaltyBreakFirstLessLess: 120 +PenaltyExcessCharacter: 1 +PenaltyReturnTypeOnItsOwnLine: 200 +PointerAlignment: Right +SpacesBeforeTrailingComments: 1 +Cpp11BracedListStyle: true +Standard: Auto +IndentWidth: 4 +TabWidth: 4 +UseTab: Always +BreakBeforeBraces: Attach + +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpacesInAngles: false +SpaceInEmptyParentheses: false +SpacesInCStyleCastParentheses: false +SpaceAfterCStyleCast: false +SpacesInContainerLiterals: false +SpaceBeforeAssignmentOperators: true + +ContinuationIndentWidth: 4 +CommentPragmas: '^ IWYU pragma:' +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] +SpaceBeforeParens: ControlStatements +DisableFormat: false +... diff --git a/src/ios/ApptentiveBridge.h b/src/ios/ApptentiveBridge.h old mode 100755 new mode 100644 index dac1834..e6637f3 --- a/src/ios/ApptentiveBridge.h +++ b/src/ios/ApptentiveBridge.h @@ -1,7 +1,8 @@ #import + @interface ApptentiveBridge : CDVPlugin -- (void)execute:(CDVInvokedUrlCommand*)command; +- (void)execute:(CDVInvokedUrlCommand *)command; -@end \ No newline at end of file +@end diff --git a/src/ios/ApptentiveBridge.m b/src/ios/ApptentiveBridge.m old mode 100755 new mode 100644 index 4ae424b..ab2b641 --- a/src/ios/ApptentiveBridge.m +++ b/src/ios/ApptentiveBridge.m @@ -3,412 +3,376 @@ #import "ApptentiveBridge.h" -@implementation ApptentiveBridge { - BOOL apptentiveInitted; - BOOL registeredForMessageNotifications; - NSString* messageNotificationCallback; +@implementation ApptentiveBridge { + BOOL apptentiveInitted; + BOOL registeredForMessageNotifications; + NSString *messageNotificationCallback; } -- (void)execute:(CDVInvokedUrlCommand*)command { - NSString* callbackId = [command callbackId]; - if ([command arguments].count == 0) { - [self sendFailureMessage:@"Insufficient arguments: No method name specified." callbackId:callbackId]; - return; - } - NSString* functionCall = [command argumentAtIndex:0]; - NSLog(@"Function call: %@",functionCall); - - //initialization - if ([functionCall isEqualToString:@"deviceReady"]) { - [self initAPIKey:callbackId]; - return; - } - if (!apptentiveInitted) { - [self sendFailureMessage:@"Apptentive API key is not set" callbackId:callbackId]; - return; - } - - //all other functions - if ([functionCall isEqualToString:@"addCustomDeviceData"]) { - [self addCustomDeviceData:[command arguments] callBackString:callbackId]; - } - else if ([functionCall isEqualToString:@"addCustomPersonData"]) { - [self addCustomPersonData:[command arguments] callBackString:callbackId]; - } - else if ([functionCall isEqualToString:@"engage"]) { - [self engage:[command arguments] callBackString:callbackId]; - } - else if ([functionCall isEqualToString:@"openAppStore"]) { - [self openAppStore]; - } - else if ([functionCall isEqualToString:@"showMessageCenter"]) { - [self showMessageCenter:[command arguments] callBackString:callbackId]; - } - else if ([functionCall isEqualToString:@"registerForMessageNotifications"]) { - [self registerForMessageNotifications:[command arguments] callBackString:callbackId]; - } - else if ([functionCall isEqualToString:@"removeCustomDeviceData"]) { - [self removeCustomDeviceData:[command arguments] callBackString:callbackId]; - } - else if ([functionCall isEqualToString:@"removeCustomPersonData"]) { - [self removeCustomPersonData:[command arguments] callBackString:callbackId]; - } - else if ([functionCall isEqualToString:@"sendAttachmentFileWithMimeType"]) { - [self sendAttachmentFileWithMimeType:[command arguments] callBackString:callbackId]; - } - else if ([functionCall isEqualToString:@"sendAttachmentImage"]) { - [self sendAttachmentImage:[command arguments] callBackString:callbackId]; - } - else if ([functionCall isEqualToString:@"sendAttachmentText"]) { - [self sendAttachmentText:[command arguments] callBackString:callbackId]; - } - else if ([functionCall isEqualToString:@"setProperty"]) { - [self setProperty:[command arguments] callBackString:callbackId]; - } - else if ([functionCall isEqualToString:@"getProperty"]) { - [self getProperty:[command arguments] callBackString:callbackId]; - } - else if ([functionCall isEqualToString:@"unreadMessageCount"]) { - [self unreadMessageCount:callbackId]; - } - else if ([functionCall isEqualToString:@"unregisterForNotifications"]) { - [self unregisterForNotifications]; - } - else if ([functionCall isEqualToString:@"canShowInteraction"]) { - [self canShowInteraction:[command arguments] callBackString:callbackId]; - } - else if ([functionCall isEqualToString:@"canShowMessageCenter"]) { - [self canShowMessageCenter:callbackId]; - } - else if ([functionCall isEqualToString:@"login"]) { - [self login:[command arguments] callBackString:callbackId]; - } - else if ([functionCall isEqualToString:@"logout"]) { - [self logoutWithCallBackString:callbackId]; - } - else { - //command not recognized - [self sendFailureMessage:@"Command not recognized" callbackId:callbackId]; - } +- (void)execute:(CDVInvokedUrlCommand *)command { + NSString *callbackId = [command callbackId]; + if ([command arguments].count == 0) { + [self sendFailureMessage:@"Insufficient arguments: No method name specified." callbackId:callbackId]; + return; + } + NSString *functionCall = [command argumentAtIndex:0]; + NSLog(@"Function call: %@", functionCall); + //initialization + if ([functionCall isEqualToString:@"deviceReady"]) { + [self initAPIKey:callbackId]; + return; + } + if (!apptentiveInitted) { + [self sendFailureMessage:@"Apptentive API key is not set" callbackId:callbackId]; + return; + } + + //all other functions + if ([functionCall isEqualToString:@"addCustomDeviceData"]) { + [self addCustomDeviceData:[command arguments] callBackString:callbackId]; + } else if ([functionCall isEqualToString:@"addCustomPersonData"]) { + [self addCustomPersonData:[command arguments] callBackString:callbackId]; + } else if ([functionCall isEqualToString:@"engage"]) { + [self engage:[command arguments] callBackString:callbackId]; + } else if ([functionCall isEqualToString:@"openAppStore"]) { + [self openAppStore]; + } else if ([functionCall isEqualToString:@"showMessageCenter"]) { + [self showMessageCenter:[command arguments] callBackString:callbackId]; + } else if ([functionCall isEqualToString:@"registerForMessageNotifications"]) { + [self registerForMessageNotifications:[command arguments] callBackString:callbackId]; + } else if ([functionCall isEqualToString:@"removeCustomDeviceData"]) { + [self removeCustomDeviceData:[command arguments] callBackString:callbackId]; + } else if ([functionCall isEqualToString:@"removeCustomPersonData"]) { + [self removeCustomPersonData:[command arguments] callBackString:callbackId]; + } else if ([functionCall isEqualToString:@"sendAttachmentFileWithMimeType"]) { + [self sendAttachmentFileWithMimeType:[command arguments] callBackString:callbackId]; + } else if ([functionCall isEqualToString:@"sendAttachmentImage"]) { + [self sendAttachmentImage:[command arguments] callBackString:callbackId]; + } else if ([functionCall isEqualToString:@"sendAttachmentText"]) { + [self sendAttachmentText:[command arguments] callBackString:callbackId]; + } else if ([functionCall isEqualToString:@"setProperty"]) { + [self setProperty:[command arguments] callBackString:callbackId]; + } else if ([functionCall isEqualToString:@"getProperty"]) { + [self getProperty:[command arguments] callBackString:callbackId]; + } else if ([functionCall isEqualToString:@"unreadMessageCount"]) { + [self unreadMessageCount:callbackId]; + } else if ([functionCall isEqualToString:@"unregisterForNotifications"]) { + [self unregisterForNotifications]; + } else if ([functionCall isEqualToString:@"canShowInteraction"]) { + [self canShowInteraction:[command arguments] callBackString:callbackId]; + } else if ([functionCall isEqualToString:@"canShowMessageCenter"]) { + [self canShowMessageCenter:callbackId]; + } else if ([functionCall isEqualToString:@"login"]) { + [self login:[command arguments] callBackString:callbackId]; + } else if ([functionCall isEqualToString:@"logout"]) { + [self logoutWithCallBackString:callbackId]; + } else { + //command not recognized + [self sendFailureMessage:@"Command not recognized" callbackId:callbackId]; + } } -- (void)sendSuccessMessage:(NSString*)msg callbackId:(NSString *)callbackId { - CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:msg]; - [self.commandDelegate sendPluginResult:result callbackId:callbackId]; +- (void)sendSuccessMessage:(NSString *)msg callbackId:(NSString *)callbackId { + CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:msg]; + [self.commandDelegate sendPluginResult:result callbackId:callbackId]; } -- (void)sendFailureMessage:(NSString*)error callbackId:(NSString *)callbackId { - CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:error]; - [self.commandDelegate sendPluginResult:result callbackId:callbackId]; +- (void)sendFailureMessage:(NSString *)error callbackId:(NSString *)callbackId { + CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:error]; + [self.commandDelegate sendPluginResult:result callbackId:callbackId]; } -- (BOOL)parseBoolValue:(NSString*)value { - if ([value isEqualToString:@"true"] || [value isEqualToString:@"True"] || [value isEqualToString:@"yes"]) { - return YES; - } - else - return [value boolValue]; +- (BOOL)parseBoolValue:(NSString *)value { + if ([value isEqualToString:@"true"] || [value isEqualToString:@"True"] || [value isEqualToString:@"yes"]) { + return YES; + } else + return [value boolValue]; } -- (NSDictionary*)parseDictionaryFromString:(id)value { - NSDictionary *data; - if ([value isKindOfClass:[NSDictionary class]]) { - data = value; - } - else { - //custom data needs to be parsed to NSDictionary - assuming json was passed - NSData* data = [value dataUsingEncoding:NSUTF8StringEncoding]; - NSError *localError = nil; - data = [NSJSONSerialization JSONObjectWithData:data options:0 error:&localError]; - } - if (data != nil) { - return data; - } - else - return nil; +- (NSDictionary *)parseDictionaryFromString:(id)value { + NSDictionary *data; + if ([value isKindOfClass:[NSDictionary class]]) { + data = value; + } else { + //custom data needs to be parsed to NSDictionary - assuming json was passed + NSData *data = [value dataUsingEncoding:NSUTF8StringEncoding]; + NSError *localError = nil; + data = [NSJSONSerialization JSONObjectWithData:data options:0 error:&localError]; + } + if (data != nil) { + return data; + } else + return nil; } #pragma mark Initialization and Events -- (void)initAPIKey:(NSString*)callbackId { - // Access Info.plist for ApptentiveAPIKey - NSDictionary *infoPlist = [[NSBundle mainBundle] infoDictionary]; - NSString *apptentiveKey = [infoPlist objectForKey:@"ApptentiveKey"]; - NSString *apptentiveSignature = [infoPlist objectForKey:@"ApptentiveSignature"]; - NSString *pluginVersion = [infoPlist objectForKey:@"ApptentivePluginVersion"]; - - // FIXME: Do we really want to be logging this? - NSLog(@"Initializing Apptentive Apptentive App Key: %@, Apptentive App Signature: %@", apptentiveKey, apptentiveSignature); - - if (apptentiveKey.length == 0 || apptentiveSignature.length == 0) { - [self sendFailureMessage:@"Insufficient arguments - no API key." callbackId:callbackId]; - return; - } - ApptentiveConfiguration *configuration = [ApptentiveConfiguration configurationWithApptentiveKey:apptentiveKey apptentiveSignature:apptentiveSignature]; - configuration.distributionName = @"Cordova"; - configuration.distributionVersion = pluginVersion; - - [Apptentive registerWithConfiguration:configuration]; - apptentiveInitted = YES; - - NSURL *styleSheetURL = [[NSBundle mainBundle] URLForResource:@"ApptentiveStyles" withExtension:@"plist"]; - if (styleSheetURL != nil) { - Apptentive.shared.styleSheet = [[ApptentiveStyleSheet alloc] initWithContentsOfURL:styleSheetURL]; - } +- (void)initAPIKey:(NSString *)callbackId { + // Access Info.plist for ApptentiveAPIKey + NSDictionary *infoPlist = [[NSBundle mainBundle] infoDictionary]; + NSString *apptentiveKey = [infoPlist objectForKey:@"ApptentiveKey"]; + NSString *apptentiveSignature = [infoPlist objectForKey:@"ApptentiveSignature"]; + NSString *pluginVersion = [infoPlist objectForKey:@"ApptentivePluginVersion"]; + + // FIXME: Do we really want to be logging this? + NSLog(@"Initializing Apptentive Apptentive App Key: %@, Apptentive App Signature: %@", apptentiveKey, apptentiveSignature); + + if (apptentiveKey.length == 0 || apptentiveSignature.length == 0) { + [self sendFailureMessage:@"Insufficient arguments - no API key." callbackId:callbackId]; + return; + } + ApptentiveConfiguration *configuration = [ApptentiveConfiguration configurationWithApptentiveKey:apptentiveKey apptentiveSignature:apptentiveSignature]; + configuration.distributionName = @"Cordova"; + configuration.distributionVersion = pluginVersion; + + [Apptentive registerWithConfiguration:configuration]; + apptentiveInitted = YES; + + NSURL *styleSheetURL = [[NSBundle mainBundle] URLForResource:@"ApptentiveStyles" withExtension:@"plist"]; + if (styleSheetURL != nil) { + Apptentive.shared.styleSheet = [[ApptentiveStyleSheet alloc] initWithContentsOfURL:styleSheetURL]; + } } -- (void) registerForMessageNotifications:(NSArray*)arguments callBackString:(NSString*)callbackId { - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(unreadMessageCountChanged:) name:ApptentiveMessageCenterUnreadCountChangedNotification object:nil]; - registeredForMessageNotifications = YES; - messageNotificationCallback = callbackId; +- (void)registerForMessageNotifications:(NSArray *)arguments callBackString:(NSString *)callbackId { + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(unreadMessageCountChanged:) name:ApptentiveMessageCenterUnreadCountChangedNotification object:nil]; + registeredForMessageNotifications = YES; + messageNotificationCallback = callbackId; } -- (void) unregisterForNotifications { - if (registeredForMessageNotifications) { - [[NSNotificationCenter defaultCenter] removeObserver:self name:ApptentiveMessageCenterUnreadCountChangedNotification object:nil]; - registeredForMessageNotifications = NO; - messageNotificationCallback = nil; - } +- (void)unregisterForNotifications { + if (registeredForMessageNotifications) { + [[NSNotificationCenter defaultCenter] removeObserver:self name:ApptentiveMessageCenterUnreadCountChangedNotification object:nil]; + registeredForMessageNotifications = NO; + messageNotificationCallback = nil; + } } #pragma mark Notifications - (void)unreadMessageCountChanged:(NSNotification *)notification { - // Unread message count is contained in the notification's userInfo dictionary. - NSNumber *unreadMessageCount = [notification.userInfo objectForKey:@"count"]; - CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:[unreadMessageCount intValue]]; - [result setKeepCallback:[NSNumber numberWithBool:YES]]; - [self.commandDelegate sendPluginResult:result callbackId:messageNotificationCallback]; + // Unread message count is contained in the notification's userInfo dictionary. + NSNumber *unreadMessageCount = [notification.userInfo objectForKey:@"count"]; + CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:[unreadMessageCount intValue]]; + [result setKeepCallback:[NSNumber numberWithBool:YES]]; + [self.commandDelegate sendPluginResult:result callbackId:messageNotificationCallback]; } #pragma mark Properties and Interface Customization -- (void) setProperty:(NSArray*)arguments callBackString:(NSString*)callbackId { - if (arguments.count < 3) { - [self sendFailureMessage:@"Insufficient arguments for setting property" callbackId:callbackId]; - return; - } - NSString *property_id = [arguments objectAtIndex:1]; - NSString *value = [arguments objectAtIndex:2]; - if ([property_id isEqualToString:@"appID"]) { - [Apptentive sharedConnection].appID = value; - } - else if ([property_id isEqualToString:@"personName"]) { - [Apptentive sharedConnection].personName = value; - } - else if ([property_id isEqualToString:@"personEmailAddress"]) { - [Apptentive sharedConnection].personEmailAddress = value; - } - else { - [self sendFailureMessage:@"Property name not recognized" callbackId:callbackId]; - } +- (void)setProperty:(NSArray *)arguments callBackString:(NSString *)callbackId { + if (arguments.count < 3) { + [self sendFailureMessage:@"Insufficient arguments for setting property" callbackId:callbackId]; + return; + } + NSString *property_id = [arguments objectAtIndex:1]; + NSString *value = [arguments objectAtIndex:2]; + if ([property_id isEqualToString:@"appID"]) { + [Apptentive sharedConnection].appID = value; + } else if ([property_id isEqualToString:@"personName"]) { + [Apptentive sharedConnection].personName = value; + } else if ([property_id isEqualToString:@"personEmailAddress"]) { + [Apptentive sharedConnection].personEmailAddress = value; + } else { + [self sendFailureMessage:@"Property name not recognized" callbackId:callbackId]; + } } -- (void) getProperty:(NSArray*)arguments callBackString:(NSString*)callbackId { - if (arguments.count < 2) { - [self sendFailureMessage:@"Insufficient arguments for getting property" callbackId:callbackId]; - return; - } - NSString *property_id = [arguments objectAtIndex:1]; - NSString *value = nil; - if ([property_id isEqualToString:@"appID"]) { - value = [Apptentive sharedConnection].appID; - } - else if ([property_id isEqualToString:@"personName"]) { - value = [Apptentive sharedConnection].personName; - } - else if ([property_id isEqualToString:@"personEmailAddress"]) { - value = [Apptentive sharedConnection].personEmailAddress; - } - else { - [self sendFailureMessage:@"Property name not recognized" callbackId:callbackId]; - return; - } - - [self sendSuccessMessage:value callbackId:callbackId]; +- (void)getProperty:(NSArray *)arguments callBackString:(NSString *)callbackId { + if (arguments.count < 2) { + [self sendFailureMessage:@"Insufficient arguments for getting property" callbackId:callbackId]; + return; + } + NSString *property_id = [arguments objectAtIndex:1]; + NSString *value = nil; + if ([property_id isEqualToString:@"appID"]) { + value = [Apptentive sharedConnection].appID; + } else if ([property_id isEqualToString:@"personName"]) { + value = [Apptentive sharedConnection].personName; + } else if ([property_id isEqualToString:@"personEmailAddress"]) { + value = [Apptentive sharedConnection].personEmailAddress; + } else { + [self sendFailureMessage:@"Property name not recognized" callbackId:callbackId]; + return; + } + + [self sendSuccessMessage:value callbackId:callbackId]; } #pragma mark Methods -- (void) addCustomDeviceData:(NSArray*)arguments callBackString:(NSString*)callbackId { - NSString* key = [arguments objectAtIndex:1]; - id value = [arguments objectAtIndex:2]; - if ([value isKindOfClass:[NSString class]]) { - NSString* stringData = value; - [[Apptentive sharedConnection] addCustomDeviceDataString:stringData withKey:key]; - } - else if ([value isKindOfClass:[NSNumber class]] ) { - if (value == [NSNumber numberWithBool:YES] || value == [NSNumber numberWithBool:NO]) { - NSNumber* boolData = value; - [[Apptentive sharedConnection] addCustomDeviceDataBool:boolData.boolValue withKey:key]; - } else { - NSNumber* numberData = value; - [[Apptentive sharedConnection] addCustomDeviceDataNumber:numberData withKey:key]; - } - } else { - [self sendFailureMessage:@"Custom Device data type not recognized" callbackId:callbackId]; - return; - } - CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - [self.commandDelegate sendPluginResult:result callbackId:callbackId]; +- (void)addCustomDeviceData:(NSArray *)arguments callBackString:(NSString *)callbackId { + NSString *key = [arguments objectAtIndex:1]; + id value = [arguments objectAtIndex:2]; + if ([value isKindOfClass:[NSString class]]) { + NSString *stringData = value; + [[Apptentive sharedConnection] addCustomDeviceDataString:stringData withKey:key]; + } else if ([value isKindOfClass:[NSNumber class]]) { + if (value == [NSNumber numberWithBool:YES] || value == [NSNumber numberWithBool:NO]) { + NSNumber *boolData = value; + [[Apptentive sharedConnection] addCustomDeviceDataBool:boolData.boolValue withKey:key]; + } else { + NSNumber *numberData = value; + [[Apptentive sharedConnection] addCustomDeviceDataNumber:numberData withKey:key]; + } + } else { + [self sendFailureMessage:@"Custom Device data type not recognized" callbackId:callbackId]; + return; + } + CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; + [self.commandDelegate sendPluginResult:result callbackId:callbackId]; } -- (void) addCustomPersonData:(NSArray*)arguments callBackString:(NSString*)callbackId { - NSString* key = [arguments objectAtIndex:1]; - id value = [arguments objectAtIndex:2]; - if ([value isKindOfClass:[NSString class]]) { - NSString* stringData = value; - [[Apptentive sharedConnection] addCustomPersonDataString:stringData withKey:key]; - } - else if ([value isKindOfClass:[NSNumber class]] ) { - if (value == [NSNumber numberWithBool:YES] || value == [NSNumber numberWithBool:NO]) { - NSNumber* boolData = value; - [[Apptentive sharedConnection] addCustomPersonDataBool:boolData.boolValue withKey:key]; - } else { - NSNumber* numberData = value; - [[Apptentive sharedConnection] addCustomPersonDataNumber:numberData withKey:key]; - } - } else { - [self sendFailureMessage:@"Custom Person data type not recognized" callbackId:callbackId]; - return; - } - CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - [self.commandDelegate sendPluginResult:result callbackId:callbackId]; +- (void)addCustomPersonData:(NSArray *)arguments callBackString:(NSString *)callbackId { + NSString *key = [arguments objectAtIndex:1]; + id value = [arguments objectAtIndex:2]; + if ([value isKindOfClass:[NSString class]]) { + NSString *stringData = value; + [[Apptentive sharedConnection] addCustomPersonDataString:stringData withKey:key]; + } else if ([value isKindOfClass:[NSNumber class]]) { + if (value == [NSNumber numberWithBool:YES] || value == [NSNumber numberWithBool:NO]) { + NSNumber *boolData = value; + [[Apptentive sharedConnection] addCustomPersonDataBool:boolData.boolValue withKey:key]; + } else { + NSNumber *numberData = value; + [[Apptentive sharedConnection] addCustomPersonDataNumber:numberData withKey:key]; + } + } else { + [self sendFailureMessage:@"Custom Person data type not recognized" callbackId:callbackId]; + return; + } + CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; + [self.commandDelegate sendPluginResult:result callbackId:callbackId]; } -- (void)engage:(NSArray*)arguments callBackString:(NSString*)callbackId { - NSString* eventLabel = [arguments objectAtIndex:1]; - if([eventLabel isEqual:[NSNull null]]) { - [self sendFailureMessage:@"Insufficient arguments to call engage - label is null" callbackId:callbackId]; - return; - } +- (void)engage:(NSArray *)arguments callBackString:(NSString *)callbackId { + NSString *eventLabel = [arguments objectAtIndex:1]; + if ([eventLabel isEqual:[NSNull null]]) { + [self sendFailureMessage:@"Insufficient arguments to call engage - label is null" callbackId:callbackId]; + return; + } void (^completion)(BOOL) = ^void(BOOL shown) { - CDVPluginResult* result = [CDVPluginResult - resultWithStatus:CDVCommandStatus_OK - messageAsBool:shown]; - [self.commandDelegate sendPluginResult:result callbackId:callbackId]; + CDVPluginResult *result = [CDVPluginResult + resultWithStatus:CDVCommandStatus_OK + messageAsBool:shown]; + [self.commandDelegate sendPluginResult:result callbackId:callbackId]; }; - if (arguments.count == 2) { + if (arguments.count == 2) { [Apptentive.shared engage:eventLabel fromViewController:self.viewController completion:completion]; return; - } - else if (arguments.count == 3) { - NSDictionary *customData = [self parseDictionaryFromString:[arguments objectAtIndex:2]]; - if (customData == nil) { - [self sendFailureMessage:@"Improperly formed json or object for engage custom data" callbackId:callbackId]; - return; - } + } else if (arguments.count == 3) { + NSDictionary *customData = [self parseDictionaryFromString:[arguments objectAtIndex:2]]; + if (customData == nil) { + [self sendFailureMessage:@"Improperly formed json or object for engage custom data" callbackId:callbackId]; + return; + } [Apptentive.shared engage:eventLabel withCustomData:customData fromViewController:self.viewController completion:completion]; return; - } + } [self sendFailureMessage:@"Too many arguments" callbackId:callbackId]; } -- (void) openAppStore { - [[Apptentive sharedConnection] openAppStore]; +- (void)openAppStore { + [[Apptentive sharedConnection] openAppStore]; } -- (void) showMessageCenter:(NSArray*)arguments callBackString:(NSString*)callbackId { - if (arguments.count == 2) { - NSDictionary *customData = [self parseDictionaryFromString:[arguments objectAtIndex:1]]; - [[Apptentive sharedConnection] presentMessageCenterFromViewController:self.viewController withCustomData:customData]; - } else { - [[Apptentive sharedConnection] presentMessageCenterFromViewController:self.viewController]; - } +- (void)showMessageCenter:(NSArray *)arguments callBackString:(NSString *)callbackId { + if (arguments.count == 2) { + NSDictionary *customData = [self parseDictionaryFromString:[arguments objectAtIndex:1]]; + [[Apptentive sharedConnection] presentMessageCenterFromViewController:self.viewController withCustomData:customData]; + } else { + [[Apptentive sharedConnection] presentMessageCenterFromViewController:self.viewController]; + } } -- (void) removeCustomDeviceData:(NSArray*)arguments callBackString:(NSString*)callbackId { - NSString* key = [arguments objectAtIndex:1]; - [[Apptentive sharedConnection] removeCustomDeviceDataWithKey:key]; - CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - [self.commandDelegate sendPluginResult:result callbackId:callbackId]; +- (void)removeCustomDeviceData:(NSArray *)arguments callBackString:(NSString *)callbackId { + NSString *key = [arguments objectAtIndex:1]; + [[Apptentive sharedConnection] removeCustomDeviceDataWithKey:key]; + CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; + [self.commandDelegate sendPluginResult:result callbackId:callbackId]; } -- (void) removeCustomPersonData:(NSArray*)arguments callBackString:(NSString*)callbackId { - NSString* key = [arguments objectAtIndex:1]; - [[Apptentive sharedConnection] removeCustomPersonDataWithKey:key]; - CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - [self.commandDelegate sendPluginResult:result callbackId:callbackId]; +- (void)removeCustomPersonData:(NSArray *)arguments callBackString:(NSString *)callbackId { + NSString *key = [arguments objectAtIndex:1]; + [[Apptentive sharedConnection] removeCustomPersonDataWithKey:key]; + CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; + [self.commandDelegate sendPluginResult:result callbackId:callbackId]; } -- (void) sendAttachmentFileWithMimeType:(NSArray*)arguments callBackString:(NSString*)callbackId { - NSData* data = [[arguments objectAtIndex:1] dataUsingEncoding:NSUTF8StringEncoding]; - NSString* mimeType = [arguments objectAtIndex:2]; - [[Apptentive sharedConnection] sendAttachmentFile:data withMimeType:mimeType]; +- (void)sendAttachmentFileWithMimeType:(NSArray *)arguments callBackString:(NSString *)callbackId { + NSData *data = [[arguments objectAtIndex:1] dataUsingEncoding:NSUTF8StringEncoding]; + NSString *mimeType = [arguments objectAtIndex:2]; + [[Apptentive sharedConnection] sendAttachmentFile:data withMimeType:mimeType]; } -- (void) sendAttachmentImage:(NSArray*)arguments callBackString:(NSString*)callbackId { - //expecting Base64 encoded string data here - NSString* base64String = [arguments objectAtIndex:1]; - NSData* data = [[NSData alloc] initWithBase64EncodedString:base64String options:0]; - UIImage* attachmentImage = [UIImage imageWithData:data]; - if (attachmentImage == nil) { - [self sendFailureMessage:@"Image could not be constructed from the passed data" callbackId:callbackId]; - } - [[Apptentive sharedConnection] sendAttachmentImage:attachmentImage]; +- (void)sendAttachmentImage:(NSArray *)arguments callBackString:(NSString *)callbackId { + //expecting Base64 encoded string data here + NSString *base64String = [arguments objectAtIndex:1]; + NSData *data = [[NSData alloc] initWithBase64EncodedString:base64String options:0]; + UIImage *attachmentImage = [UIImage imageWithData:data]; + if (attachmentImage == nil) { + [self sendFailureMessage:@"Image could not be constructed from the passed data" callbackId:callbackId]; + } + [[Apptentive sharedConnection] sendAttachmentImage:attachmentImage]; } -- (void) sendAttachmentText:(NSArray*)arguments callBackString:(NSString*)callbackId { - NSString* text = [arguments objectAtIndex:1]; - [[Apptentive sharedConnection] sendAttachmentText:text]; +- (void)sendAttachmentText:(NSArray *)arguments callBackString:(NSString *)callbackId { + NSString *text = [arguments objectAtIndex:1]; + [[Apptentive sharedConnection] sendAttachmentText:text]; } -- (void) unreadMessageCount:(NSString*)callbackId { - NSUInteger unreadMessageCount = [[Apptentive sharedConnection] unreadMessageCount]; - CDVPluginResult* result = [CDVPluginResult - resultWithStatus:CDVCommandStatus_OK - messageAsInt:(int)unreadMessageCount]; - [self.commandDelegate sendPluginResult:result callbackId:callbackId]; +- (void)unreadMessageCount:(NSString *)callbackId { + NSUInteger unreadMessageCount = [[Apptentive sharedConnection] unreadMessageCount]; + CDVPluginResult *result = [CDVPluginResult + resultWithStatus:CDVCommandStatus_OK + messageAsInt:(int)unreadMessageCount]; + [self.commandDelegate sendPluginResult:result callbackId:callbackId]; } -- (void)canShowInteraction:(NSArray*)arguments callBackString:(NSString*)callbackId { - NSString* eventName = [arguments objectAtIndex:1]; - if([eventName isEqual:[NSNull null]]) { - [self sendFailureMessage:@"Insufficient arguments to call willShowInteraction - eventName is null" callbackId:callbackId]; - return; - } +- (void)canShowInteraction:(NSArray *)arguments callBackString:(NSString *)callbackId { + NSString *eventName = [arguments objectAtIndex:1]; + if ([eventName isEqual:[NSNull null]]) { + [self sendFailureMessage:@"Insufficient arguments to call willShowInteraction - eventName is null" callbackId:callbackId]; + return; + } [Apptentive.shared queryCanShowInteractionForEvent:eventName completion:^(BOOL canShow) { - CDVPluginResult* result = [CDVPluginResult - resultWithStatus:CDVCommandStatus_OK - messageAsBool:canShow]; + CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:canShow]; [self.commandDelegate sendPluginResult:result callbackId:callbackId]; }]; } - (void)canShowMessageCenter:(NSString *)callbackId { [Apptentive.shared queryCanShowMessageCenterWithCompletion:^(BOOL canShow) { - CDVPluginResult* result = [CDVPluginResult - resultWithStatus:CDVCommandStatus_OK - messageAsBool:canShow]; - [self.commandDelegate sendPluginResult:result callbackId:callbackId]; + CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:canShow]; + [self.commandDelegate sendPluginResult:result callbackId:callbackId]; }]; } -- (void)login:(NSArray*)arguments callBackString:(NSString*)callbackId { - NSString* token = [arguments objectAtIndex:1]; - if([token isEqual:[NSNull null]]) { - [self sendFailureMessage:@"Insufficient arguments to call login - token is nil" callbackId:callbackId]; - return; - } - [[Apptentive shared] logInWithToken:token completion:^(BOOL success, NSError * _Nonnull error) { - CDVPluginResult* result; - if (success) { - result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - } else { - result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error localizedDescription]]; - } - [self.commandDelegate sendPluginResult:result callbackId:callbackId]; - }]; +- (void)login:(NSArray *)arguments callBackString:(NSString *)callbackId { + NSString *token = [arguments objectAtIndex:1]; + if ([token isEqual:[NSNull null]]) { + [self sendFailureMessage:@"Insufficient arguments to call login - token is nil" callbackId:callbackId]; + return; + } + [[Apptentive shared] logInWithToken:token completion:^(BOOL success, NSError *_Nonnull error) { + CDVPluginResult *result; + if (success) { + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; + } else { + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error localizedDescription]]; + } + [self.commandDelegate sendPluginResult:result callbackId:callbackId]; + }]; } -- (void)logoutWithCallBackString:(NSString*)callbackId { - [[Apptentive shared] logOut]; - CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - [self.commandDelegate sendPluginResult:result callbackId:callbackId]; +- (void)logoutWithCallBackString:(NSString *)callbackId { + [[Apptentive shared] logOut]; + CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; + [self.commandDelegate sendPluginResult:result callbackId:callbackId]; } @end