diff --git a/CHANGELOG.md b/CHANGELOG.md index 35250ae..583c322 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,15 @@ This document lets you know what has changed in the Cordova plugin. For changes - [Android Changelog](https://github.com/apptentive/apptentive-android/blob/master/CHANGELOG.md) - [iOS Changelog](https://github.com/apptentive/apptentive-ios/blob/master/CHANGELOG.md) +# 2022-04-13 - v5.8.4 + +**Fixes** +- Add registerWithLogs() to set Apptentive log level +- Add missing callback calls to iOS registration function + +- Apptentive Android SDK: 5.8.3 +- Apptentive iOS SDK: 5.3.4 + # 2022-03-23 - v5.8.3 - Apptentive Android SDK: 5.8.3 diff --git a/package.json b/package.json index a5e52a7..6f99da9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "apptentive-cordova", - "version": "5.8.3", + "version": "5.8.4", "description": "Apptentive Plugin For Cordova", "cordova": { "id": "apptentive-cordova", diff --git a/plugin.xml b/plugin.xml index df8a8b3..0c01622 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + Apptentive Apptentive Plugin For Cordova @@ -42,7 +42,7 @@ Cordova - 5.8.3 + 5.8.4 @@ -75,7 +75,7 @@ - 5.8.3 + 5.8.4 diff --git a/src/android/ApptentiveBridge.java b/src/android/ApptentiveBridge.java index 20efdd8..4d243d6 100644 --- a/src/android/ApptentiveBridge.java +++ b/src/android/ApptentiveBridge.java @@ -69,6 +69,16 @@ public boolean execute(final String action, JSONArray args, final CallbackContex @Override public void run() { ApptentiveConfiguration configuration = resolveConfiguration(currentActivity.getApplication()); + + // Parse log level, info by default + String newLogLevel; + try { + newLogLevel = args.getString(0); + } catch (JSONException e) { + newLogLevel = "info"; + } + configuration.setLogLevel(parseLogLevel(newLogLevel)); + Apptentive.register(currentActivity.getApplication(), configuration); Application.ActivityLifecycleCallbacks callbacks = ApptentiveActivityLifecycleCallbacks.getInstance(); if (callbacks != null) { @@ -292,6 +302,16 @@ public void onLoginFail(String errorMessage) { return false; } + private static ApptentiveLog.Level parseLogLevel(String logLevel) { + if (logLevel.equals("verbose")) { return ApptentiveLog.Level.VERBOSE; } + if (logLevel.equals("debug")) { return ApptentiveLog.Level.DEBUG; } + if (logLevel.equals("info")) { return ApptentiveLog.Level.INFO; } + if (logLevel.equals("warn")) { return ApptentiveLog.Level.WARN; } + if (logLevel.equals("error")) { return ApptentiveLog.Level.ERROR; } + if (logLevel.equals("assert")) { return ApptentiveLog.Level.ASSERT; } + return ApptentiveLog.Level.UNKNOWN; + } + private static ApptentiveConfiguration resolveConfiguration(Context context) { String apptentiveKey = Util.getManifestMetadataString(context, Constants.MANIFEST_KEY_APPTENTIVE_KEY); if (StringUtils.isNullOrEmpty(apptentiveKey)) { diff --git a/src/ios/ApptentiveBridge.m b/src/ios/ApptentiveBridge.m index c9ba2c8..c9ad674 100644 --- a/src/ios/ApptentiveBridge.m +++ b/src/ios/ApptentiveBridge.m @@ -20,7 +20,12 @@ - (void)execute:(CDVInvokedUrlCommand *)command { //initialization if ([functionCall isEqualToString:@"deviceReady"]) { - [self initAPIKey:callbackId]; + // Set log level if present, info level by default + if ([command arguments].count == 2) { + [self initAPIKey:callbackId withLogLevel:[command argumentAtIndex:1]]; + } else { + [self initAPIKey:callbackId withLogLevel:@"info"]; + } return; } if (!apptentiveInitialized) { @@ -107,15 +112,17 @@ - (NSDictionary *)parseDictionaryFromString:(id)value { } #pragma mark Initialization and Events -- (void)initAPIKey:(NSString *)callbackId { +- (void)initAPIKey:(NSString *)callbackId withLogLevel:(NSString *)logLevel { // 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); + // Log key and signature with verbose logs + if ([logLevel isEqualToString:@"verbose"]) { + 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]; @@ -124,14 +131,17 @@ - (void)initAPIKey:(NSString *)callbackId { if (Apptentive.shared.apptentiveKey.length > 0 && Apptentive.shared.apptentiveSignature.length > 0) { if (![Apptentive.shared.apptentiveKey isEqualToString:apptentiveKey] || ![Apptentive.shared.apptentiveSignature isEqualToString:apptentiveSignature]) { NSLog(@"Apptentive key or signature mismatch. The SDK is not initialized."); + [self sendFailureMessage:@"Apptentive key or signature mismatch. The SDK is not initialized." callbackId:callbackId]; return; } - NSLog(@"WARNING: Apptentive instance is already initialized!"); + [self sendFailureMessage:@"Apptentive instance is already initialized." callbackId:callbackId]; + return; } else { ApptentiveConfiguration *configuration = [ApptentiveConfiguration configurationWithApptentiveKey:apptentiveKey apptentiveSignature:apptentiveSignature]; configuration.distributionName = @"Cordova"; configuration.distributionVersion = pluginVersion; + configuration.logLevel = [self parseLogLevel:logLevel]; [Apptentive registerWithConfiguration:configuration]; } @@ -141,6 +151,18 @@ - (void)initAPIKey:(NSString *)callbackId { if (styleSheetURL != nil) { Apptentive.shared.styleSheet = [[ApptentiveStyleSheet alloc] initWithContentsOfURL:styleSheetURL]; } + + [self sendSuccessMessage:@"Apptentive initialized" callbackId:callbackId]; +} + +- (ApptentiveLogLevel)parseLogLevel:(NSString *) logLevel { + if ([logLevel isEqualToString:@"verbose"]) { return ApptentiveLogLevelVerbose; } + if ([logLevel isEqualToString:@"debug"]) { return ApptentiveLogLevelDebug; } + if ([logLevel isEqualToString:@"info"]) { return ApptentiveLogLevelInfo; } + if ([logLevel isEqualToString:@"warn"]) { return ApptentiveLogLevelWarn; } + if ([logLevel isEqualToString:@"error"]) { return ApptentiveLogLevelError; } + if ([logLevel isEqualToString:@"critical"]) { return ApptentiveLogLevelCrit; } + return ApptentiveLogLevelUndefined; } - (void)registerForMessageNotifications:(NSArray *)arguments callBackString:(NSString *)callbackId { diff --git a/www/ApptentiveAndroid.js b/www/ApptentiveAndroid.js index 8fc2efd..285dd4e 100644 --- a/www/ApptentiveAndroid.js +++ b/www/ApptentiveAndroid.js @@ -12,6 +12,11 @@ var Apptentive = { cordova.exec(successCallback, errorCallback, "ApptentiveBridge", "deviceReady", []); }, + registerWithLogs: function (successCallback, errorCallback, loglevel) { + console.log("Apptentive.registerWithLogs()"); + cordova.exec(successCallback, errorCallback, "ApptentiveBridge", "deviceReady", [loglevel]); + }, + engage: function (successCallback, errorCallback, eventName, customData) { if (customData && typeof customData === 'object') { cordova.exec(successCallback, errorCallback, "ApptentiveBridge", "engage", [eventName, customData]); diff --git a/www/ApptentiveIos.js b/www/ApptentiveIos.js index 26d1d4d..accc224 100644 --- a/www/ApptentiveIos.js +++ b/www/ApptentiveIos.js @@ -15,6 +15,12 @@ var Apptentive = { cordova.exec(successCallback, errorCallback, "ApptentiveBridge", "execute", ["deviceReady"]); }, + registerWithLogs: function (successCallback, errorCallback, loglevel) { + console.log("Apptentive.registerWithLogs()"); + Apptentive.initialized = true; + cordova.exec(successCallback, errorCallback, "ApptentiveBridge", "execute", ["deviceReady", loglevel]); + }, + engage: function (successCallback, errorCallback, eventName, customData) { if (customData) { cordova.exec(successCallback, errorCallback, "ApptentiveBridge", "execute", ["engage", eventName, customData]);