From 12fe9502da8847e415209008b24a262d9e4f9004 Mon Sep 17 00:00:00 2001 From: Jeriel Ng Date: Thu, 8 Feb 2024 11:51:19 -0500 Subject: [PATCH] Release Cordova SDK version 8.0.0 --- CHANGELOG.md | 102 +++++++++++------- package.json | 2 +- plugin.xml | 8 +- sample-project/config.xml | 23 +++- sample-project/hooks/replace-entitlements.js | 22 ++++ .../res/HelloCordova-Debug.entitlements | 17 +++ .../res/HelloCordova-Release.entitlements | 17 +++ sample-project/www/js/index.js | 11 +- src/android/BrazePlugin.kt | 21 +++- src/android/ContentCardUtils.kt | 6 +- src/android/build-extras.gradle | 2 +- src/ios/BrazePlugin.m | 65 ++++++++++- www/BrazePlugin.js | 23 +--- 13 files changed, 237 insertions(+), 82 deletions(-) create mode 100644 sample-project/hooks/replace-entitlements.js create mode 100644 sample-project/res/HelloCordova-Debug.entitlements create mode 100644 sample-project/res/HelloCordova-Release.entitlements diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f147ac..9655801 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,23 @@ +## 8.0.0 + +##### Breaking +- Updated the native Android bridge [from Braze Android SDK 27.0.1 to 30.0.0](https://github.com/braze-inc/braze-android-sdk/compare/v27.0.0...v30.0.0#diff-06572a96a58dc510037d5efa622f9bec8519bc1beab13c9f251e97e657a9d4ed). +- Updated the native iOS bridge [from Braze Swift SDK 6.6.0 to 7.6.0](https://github.com/braze-inc/braze-swift-sdk/compare/6.6.0...7.6.0#diff-06572a96a58dc510037d5efa622f9bec8519bc1beab13c9f251e97e657a9d4ed). +- Renamed the `Banner` Content Card type to `ImageOnly`: + - `ContentCardTypes.BANNER` → `ContentCardTypes.IMAGE_ONLY` + - On Android, if the XML files in your project contain the word `banner` for Content Cards, it should be replaced with `image_only`. +- `BrazePlugin.getFeatureFlag(id)` will now return `null` if the feature flag does not exist. +- `BrazePlugin.subscribeToFeatureFlagsUpdates(function)` will only trigger when a refresh request completes with success or failure, and upon initial subscription if there was previously cached data from the current session. +- Removed the deprecated method `registerAppboyPushMessages`. Use `setRegisteredPushToken` instead. + +##### Added +- Added the ability to set a minimum trigger action time interval for Android and iOS. + - To enable this feature, add the line `` in your `config.xml`. +- Added the ability to configure the app group ID for iOS push extensions. + - To enable this feature, add the line `` in your `config.xml`. +- Added support for automatically forwarding universal links in iOS. + - To enable this feature, add the line `` in your `config.xml`. + ## 7.0.0 ##### Breaking @@ -90,7 +110,7 @@ ## 2.32.0 ##### Breaking -- Updated to [Braze Android SDK 24.1.0](https://github.com/Appboy/appboy-android-sdk/releases/tag/v24.1.0). +- Updated to [Braze Android SDK 24.1.0](https://github.com/braze-inc/braze-android-sdk/releases/tag/v24.1.0). - Updated the Android bridge to Kotlin. - `` is now required in your `config.xml`. - Removed `setAvatarImageUrl()`. @@ -104,7 +124,7 @@ ## 2.31.0 ##### Breaking -- Updated to [Braze Android SDK 23.0.1](https://github.com/Appboy/appboy-android-sdk/releases/tag/v23.0.1). +- Updated to [Braze Android SDK 23.0.1](https://github.com/braze-inc/braze-android-sdk/releases/tag/v23.0.1). ##### Added - Added a method `requestPushPermission()` for Android API 33 to request push permission prompts from the system on Android 13 devices. @@ -121,21 +141,21 @@ ## 2.30.0 ##### Breaking -- Updated to [Braze Android SDK 21.0.0](https://github.com/Appboy/appboy-android-sdk/releases/tag/v21.0.0). +- Updated to [Braze Android SDK 21.0.0](https://github.com/braze-inc/braze-android-sdk/releases/tag/v21.0.0). - Removed "logContentCardsDisplayed" from the javascript plugin. ## 2.29.0 ##### Breaking -- Updated to [Braze Android SDK 19.0.0](https://github.com/Appboy/appboy-android-sdk/releases/tag/v19.0.0). +- Updated to [Braze Android SDK 19.0.0](https://github.com/braze-inc/braze-android-sdk/releases/tag/v19.0.0). ##### Changed -- Updated to [Braze iOS SDK 4.4.2](https://github.com/Appboy/appboy-ios-sdk/releases/tag/4.4.2). +- Updated to [Braze iOS SDK 4.4.2](https://github.com/braze-inc/braze-ios-sdk/releases/tag/4.4.2). ## 2.28.0 ##### Breaking -- Updated to [Braze Android SDK 18.0.1](https://github.com/Appboy/appboy-android-sdk/releases/tag/v18.0.1). +- Updated to [Braze Android SDK 18.0.1](https://github.com/braze-inc/braze-android-sdk/releases/tag/v18.0.1). ##### Fixed - Fixed an error around locating certain iOS resources when integrating the SDK. @@ -143,8 +163,8 @@ ## 2.27.0 ##### Breaking -- Updated to [Braze Android SDK 17.0.0](https://github.com/Appboy/appboy-android-sdk/releases/tag/v17.0.0). -- Updated to [Braze iOS SDK 4.4.0](https://github.com/Appboy/appboy-ios-sdk/releases/tag/4.4.0). +- Updated to [Braze Android SDK 17.0.0](https://github.com/braze-inc/braze-android-sdk/releases/tag/v17.0.0). +- Updated to [Braze iOS SDK 4.4.0](https://github.com/braze-inc/braze-ios-sdk/releases/tag/4.4.0). ##### Added - Added `addToSubscriptionGroup()` and `removeFromSubscriptionGroup()`. @@ -152,7 +172,7 @@ ## 2.26.0 ##### Breaking -- Updated to [Braze Android SDK 16.0.0](https://github.com/Appboy/appboy-android-sdk/releases/tag/v16.0.0). +- Updated to [Braze Android SDK 16.0.0](https://github.com/braze-inc/braze-android-sdk/releases/tag/v16.0.0). ##### Fixed - Fixed an issue in pre Android P WebViews where the system WebView would not properly handle view focus being returned to it. @@ -163,10 +183,10 @@ ## 2.25.0 ##### Breaking -- Updated to [Braze Android SDK 15.0.0](https://github.com/Appboy/appboy-android-sdk/releases/tag/v15.0.0). +- Updated to [Braze Android SDK 15.0.0](https://github.com/braze-inc/braze-android-sdk/releases/tag/v15.0.0). ##### Changed -- Updated to [Braze iOS SDK 4.3.2](https://github.com/Appboy/appboy-ios-sdk/releases/tag/4.3.2). +- Updated to [Braze iOS SDK 4.3.2](https://github.com/braze-inc/braze-ios-sdk/releases/tag/4.3.2). ##### Added - Added `Other`, `Unknown`, `Not Applicable`, and `Prefer not to Say` options for user gender. @@ -174,8 +194,8 @@ ## 2.24.0 ##### Breaking -- Updated to [Braze Android SDK 14.0.1](https://github.com/Appboy/appboy-android-sdk/releases/tag/v14.0.1). -- Updated to [Braze iOS SDK 4.3.0](https://github.com/Appboy/appboy-ios-sdk/releases/tag/4.3.0). +- Updated to [Braze Android SDK 14.0.1](https://github.com/braze-inc/braze-android-sdk/releases/tag/v14.0.1). +- Updated to [Braze iOS SDK 4.3.0](https://github.com/braze-inc/braze-ios-sdk/releases/tag/4.3.0). ##### Changed - (minor) Changed logcat tag for Android plugin to be `BrazeCordova`. @@ -183,12 +203,12 @@ ## 2.23.0 ##### Breaking -- Updated to [Braze Android SDK 13.1.2](https://github.com/Appboy/appboy-android-sdk/releases/tag/v13.1.2). +- Updated to [Braze Android SDK 13.1.2](https://github.com/braze-inc/braze-android-sdk/blob/master/CHANGELOG.md#1312). ## 2.22.0 ##### Breaking -- Updated to [Braze Android SDK 13.0.0](https://github.com/Appboy/appboy-android-sdk/releases/tag/v13.0.0). +- Updated to [Braze Android SDK 13.0.0](https://github.com/braze-inc/braze-android-sdk/releases/tag/v13.0.0). ##### Added - Added the ability to delay automatic session tracking for Android. @@ -197,7 +217,7 @@ ## 2.21.0 ##### Breaking -- Updated to [Braze iOS SDK 3.31.1](https://github.com/Appboy/appboy-ios-sdk/releases/tag/3.31.1). +- Updated to [Braze iOS SDK 3.31.1](https://github.com/braze-inc/braze-ios-sdk/blob/master/CHANGELOG.md#3311). ##### Fixed - Fixed an issue on iOS where the plugin was incompatible with other Cordova plugins that have the `use_frameworks` Cocoapods setting in their `Podfile`. @@ -213,8 +233,8 @@ ## 2.19.0 ##### Breaking -- Updated to [Braze iOS SDK 3.29.1](https://github.com/Appboy/appboy-ios-sdk/releases/tag/3.29.1). -- Updated to [Braze Android SDK 11.0.0](https://github.com/Appboy/appboy-android-sdk/releases/tag/v11.0.0). +- Updated to [Braze iOS SDK 3.29.1](https://github.com/braze-inc/braze-ios-sdk/blob/master/CHANGELOG.md#3291). +- Updated to [Braze Android SDK 11.0.0](https://github.com/braze-inc/braze-android-sdk/releases/tag/v11.0.0). ##### Fixed - Fixed an issue where the plugin would automatically add the In-app Purchase capability to XCode projects. @@ -225,18 +245,18 @@ ## 2.18.0 ##### Breaking -- Updated to [Braze Android SDK 10.0.0](https://github.com/Appboy/appboy-android-sdk/releases/tag/v10.0.0). +- Updated to [Braze Android SDK 10.0.0](https://github.com/braze-inc/braze-android-sdk/releases/tag/v10.0.0). ## 2.17.0 ##### Breaking -- The native iOS bridge uses [Braze iOS SDK 3.27.0](https://github.com/Appboy/appboy-ios-sdk/blob/master/CHANGELOG.md#3270). This release adds support for iOS 14 and requires XCode 12. Please read the Braze iOS SDK changelog for details. +- The native iOS bridge uses [Braze iOS SDK 3.27.0](https://github.com/braze-inc/braze-ios-sdk/blob/master/CHANGELOG.md#3270). This release adds support for iOS 14 and requires XCode 12. Please read the Braze iOS SDK changelog for details. ## 2.16.0 ##### Changed -- Updated to [Braze Android SDK 8.1.0](https://github.com/Appboy/appboy-android-sdk/releases/tag/v8.1.0). -- Updated to [Braze iOS SDK 3.26.1](https://github.com/Appboy/appboy-ios-sdk/releases/tag/3.26.1). +- Updated to [Braze Android SDK 8.1.0](https://github.com/braze-inc/braze-android-sdk/releases/tag/v8.1.0). +- Updated to [Braze iOS SDK 3.26.1](https://github.com/braze-inc/braze-ios-sdk/blob/master/CHANGELOG.md#3261). ##### Added - Added the ability to display notifications while app is in the foreground in iOS. Within `config.xml` set `com.appboy.display_foreground_push_notifications` to `"YES"` to enable this. @@ -244,14 +264,14 @@ ## 2.15.0 ##### Changed -- Updated to [Braze iOS SDK 3.23.0](https://github.com/Appboy/appboy-ios-sdk/releases/tag/3.23.0). -- Updated to [Braze Android SDK 8.0.1](https://github.com/Appboy/appboy-android-sdk/releases/tag/v8.0.1). +- Updated to [Braze iOS SDK 3.23.0](https://github.com/braze-inc/braze-ios-sdk/blob/master/CHANGELOG.md#3230). +- Updated to [Braze Android SDK 8.0.1](https://github.com/braze-inc/braze-android-sdk/releases/tag/v8.0.1). ## 2.14.0 ##### Changed - Reverted iOS plugin to use framework tag in `plugin.xml`. -- Updated to [Braze Android SDK 7.0.0](https://github.com/Appboy/appboy-android-sdk/releases/tag/v7.0.0). +- Updated to [Braze Android SDK 7.0.0](https://github.com/braze-inc/braze-android-sdk/releases/tag/v7.0.0). ## 2.13.0 @@ -260,39 +280,39 @@ - `getContentCardsFromServer(), getContentCardsFromCache()` both take a success and error callback to handle return values. ##### Changed -- Updated to [Braze Android SDK 4.0.2](https://github.com/Appboy/appboy-android-sdk/releases/tag/v4.0.2). +- Updated to [Braze Android SDK 4.0.2](https://github.com/braze-inc/braze-android-sdk/releases/tag/v4.0.2). ## 2.12.0 ##### Changed -- Updated to [Braze Android SDK 3.8.0](https://github.com/Appboy/appboy-android-sdk/releases/tag/v3.8.0). +- Updated to [Braze Android SDK 3.8.0](https://github.com/braze-inc/braze-android-sdk/releases/tag/v3.8.0). - Pinned Android Gradle plugin version to 3.5.1 in `build-extras.gradle`. - - Addresses https://github.com/Appboy/appboy-cordova-sdk/issues/46. + - Addresses https://github.com/braze-inc/braze-cordova-sdk/issues/46. ## 2.11.2 -**Important:** This patch updates the Braze iOS SDK Dependency from 3.20.1 to 3.20.2, which contains important bugfixes. Integrators should upgrade to this patch version. Please see the [Braze iOS SDK Changelog](https://github.com/Appboy/appboy-ios-sdk/blob/master/CHANGELOG.md) for more information. +**Important:** This patch updates the Braze iOS SDK Dependency from 3.20.1 to 3.20.2, which contains important bugfixes. Integrators should upgrade to this patch version. Please see the [Braze iOS SDK Changelog](https://github.com/braze-inc/braze-ios-sdk/blob/master/CHANGELOG.md) for more information. ##### Changed -- Updated to [Braze iOS SDK 3.20.2](https://github.com/Appboy/appboy-ios-sdk/releases/tag/3.20.2). +- Updated to [Braze iOS SDK 3.20.2](https://github.com/braze-inc/braze-ios-sdk/blob/master/CHANGELOG.md#3202). ## 2.11.1 **Important:** This release has known issues displaying HTML in-app messages. Do not upgrade to this version and upgrade to 2.11.2 and above instead. If you are using this version, you are strongly encouraged to upgrade to 2.11.2 or above if you make use of HTML in-app messages. ##### Changed -- Updated to [Braze iOS SDK 3.20.1](https://github.com/Appboy/appboy-ios-sdk/releases/tag/3.20.1). +- Updated to [Braze iOS SDK 3.20.1](https://github.com/braze-inc/braze-ios-sdk/blob/master/CHANGELOG.md#3201). ## 2.11.0 **Important:** This release has known issues displaying HTML in-app messages. Do not upgrade to this version and upgrade to 2.11.2 and above instead. If you are using this version, you are strongly encouraged to upgrade to 2.11.2 or above if you make use of HTML in-app messages. ##### Breaking -- Updated to [Braze iOS SDK 3.20.0](https://github.com/Appboy/appboy-ios-sdk/releases/tag/3.20.0). +- Updated to [Braze iOS SDK 3.20.0](https://github.com/braze-inc/braze-ios-sdk/blob/master/CHANGELOG.md#3200). - **Important:** Braze iOS SDK 3.20.0 contains updated push token registration methods. We recommend upgrading to this version as soon as possible to ensure a smooth transition as devices upgrade to iOS 13. - Removes the Feedback feature. - `submitFeedback()` and `launchFeedback()` have been removed from the `AppboyPlugin` interface. -- Updated to [Braze Android SDK 3.7.0](https://github.com/Appboy/appboy-android-sdk/releases/tag/v3.7.0). +- Updated to [Braze Android SDK 3.7.0](https://github.com/braze-inc/braze-android-sdk/releases/tag/v3.7.0). ##### Added - Added ability to configure location collection in preferences. Braze location collection is now disabled by default. @@ -310,7 +330,7 @@ ## 2.10.0 ##### Breaking -- Updated to [Braze iOS SDK 3.14.1](https://github.com/Appboy/appboy-ios-sdk/releases/tag/3.14.1). +- Updated to [Braze iOS SDK 3.14.1](https://github.com/braze-inc/braze-ios-sdk/blob/master/CHANGELOG.md#3141). ##### Added - Added ability for plugin to automatically collect the IDFA information on iOS. To enable, set `com.appboy.ios_enable_idfa_automatic_collection` to `YES` in your `config.xml` project file. @@ -322,13 +342,13 @@ ##### Fixed - Fixed an issue in the Android plugin where the Braze SDK could be invoked before `pluginInitialize` was called by Cordova. The plugin now explicitly initializes the SDK before any SDK or Android lifecycle methods are called. - - Fixes https://github.com/Appboy/appboy-cordova-sdk/issues/38 + - Fixes https://github.com/braze-inc/braze-cordova-sdk/issues/38 ## 2.9.0 ##### Breaking -- Updated to [Braze iOS SDK 3.14.0](https://github.com/Appboy/appboy-ios-sdk/releases/tag/3.14.0). -- Updated to [Braze Android SDK 3.2.2](https://github.com/Appboy/appboy-android-sdk/blob/master/CHANGELOG.md#322). +- Updated to [Braze iOS SDK 3.14.0](https://github.com/braze-inc/braze-ios-sdk/blob/master/CHANGELOG.md#3140). +- Updated to [Braze Android SDK 3.2.2](https://github.com/braze-inc/braze-android-sdk/blob/master/CHANGELOG.md#322). ##### Changed - Changed the iOS plugin to use Cocoapods instead of a framework integration. @@ -336,7 +356,7 @@ ##### Fixed - Fixed the Android plugin not respecting decimal purchase prices. - - Fixes https://github.com/Appboy/appboy-cordova-sdk/issues/36. + - Fixes https://github.com/braze-inc/braze-cordova-sdk/issues/36. ## 2.8.0 - Changed the iOS frameworks to be automatically embedded in the `plugin.xml`. @@ -390,7 +410,7 @@ - Updates Appboy Android version to 1.18+ - Updates Appboy iOS version to 2.25.0 - Adds the ability to configure the Android Cordova SDK using the config.xml. See the Android sample-project's `config.xml` for an example. - - Supported keys below, see [the AppboyConfig.Builder javadoc](http://appboy.github.io/appboy-android-sdk/javadocs/com/appboy/configuration/AppboyConfig.Builder.html) for more details + - Supported keys below, see [the AppboyConfig.Builder javadoc](https://appboy.github.io/appboy-android-sdk/javadocs/com/braze/configuration/BrazeConfig.Builder.html) for more details - "com.appboy.api_key" (String) - "com.appboy.android_automatic_push_registration_enabled" ("true"/"false") - "com.appboy.android_gcm_sender_id" (String) @@ -400,7 +420,7 @@ - "com.appboy.android_default_session_timeout" (String) - "com.appboy.android_handle_push_deep_links_automatically" ("true"/"false") - "com.appboy.android_log_level" (Integer) can also be configured here, for obtaining debug logs from the Appboy Android SDK -- Updates the Android Cordova SDK to use the [Appboy Lifecycle listener](http://appboy.github.io/appboy-android-sdk/javadocs/com/appboy/AppboyLifecycleCallbackListener.html) to handle session and in-app message registration +- Updates the Android Cordova SDK to use the [Appboy Lifecycle listener](https://appboy.github.io/appboy-android-sdk/javadocs/com/braze/BrazeActivityLifecycleCallbackListener.html) to handle session and in-app message registration ## 2.1.0 - Adds support for iOS 10 push registration and handling using the UNUserNotificationCenter. @@ -408,7 +428,7 @@ ## 2.0.0 - Updates to add functionality for turning off automatic push registration on iOS. If you want to turn off iOS default push registration, add the preference `com.appboy.ios_disable_automatic_push_registration` with a value of `YES`. -- Includes patch for iOS 10 push open bug. See https://github.com/Appboy/appboy-ios-sdk/releases/tag/2.24.0 for more information. +- Includes patch for iOS 10 push open bug. See https://github.com/braze-inc/braze-ios-sdk/blob/master/CHANGELOG.md#2240 for more information. - Updates Appboy iOS version to 2.24.2. - Updates Appboy Android version to 1.15+. - Updates plugin to configure Android via parameters to eliminate need for post-install modifications on Android. Ported from https://github.com/Appboy/appboy-cordova-sdk/tree/feature/android-variable-integration. diff --git a/package.json b/package.json index 2166b0f..d602185 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { "name": "braze-cordova-sdk", - "version": "7.0.0", + "version": "8.0.0", "main": "www/BrazePlugin.js" } diff --git a/plugin.xml b/plugin.xml index 8ba7f05..7a4a7d2 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,6 +1,6 @@ + id="cordova-plugin-braze" version="8.0.0"> Device Braze Cordova SDK MIT @@ -54,9 +54,9 @@ - - - + + + diff --git a/sample-project/config.xml b/sample-project/config.xml index 8f99986..7683952 100755 --- a/sample-project/config.xml +++ b/sample-project/config.xml @@ -1,10 +1,10 @@ - - + HelloCordova A sample Apache Cordova application for the Braze SDK. @@ -40,6 +40,7 @@ + + + + + + + + remote-notification + + + + + diff --git a/sample-project/hooks/replace-entitlements.js b/sample-project/hooks/replace-entitlements.js new file mode 100644 index 0000000..bc66dd2 --- /dev/null +++ b/sample-project/hooks/replace-entitlements.js @@ -0,0 +1,22 @@ +var xcode = require('xcode'), + fs = require('fs'), + path = require('path'); + +module.exports = function(context) { + var projectRoot = context.opts.projectRoot; + var xcconfigPath = path.join(projectRoot, 'platforms', 'ios', 'cordova', 'build.xcconfig'); + var xcconfigContents = fs.readFileSync(xcconfigPath, 'utf-8'); + + var entitlementsLine = 'CODE_SIGN_ENTITLEMENTS = $(PROJECT_DIR)/$(PROJECT_NAME)/Resources/HelloCordova-$(CONFIGURATION).entitlements'; + var regex = /^CODE_SIGN_ENTITLEMENTS = .*/m; + + if (xcconfigContents.match(regex)) { + // If the line exists, replace it. + xcconfigContents = xcconfigContents.replace(regex, entitlementsLine); + } else { + // If the line doesn't exist, add it. + xcconfigContents += '\n' + entitlementsLine; + } + + fs.writeFileSync(xcconfigPath, xcconfigContents, 'utf-8'); +}; \ No newline at end of file diff --git a/sample-project/res/HelloCordova-Debug.entitlements b/sample-project/res/HelloCordova-Debug.entitlements new file mode 100644 index 0000000..985e679 --- /dev/null +++ b/sample-project/res/HelloCordova-Debug.entitlements @@ -0,0 +1,17 @@ + + + + + aps-environment + development + com.apple.security.application-groups + + group.com.braze.hellocordova.PushStories + + com.apple.developer.associated-domains + + applinks:cdv.universal.braze.com + applinks:cdv.universal.example.com + + + diff --git a/sample-project/res/HelloCordova-Release.entitlements b/sample-project/res/HelloCordova-Release.entitlements new file mode 100644 index 0000000..fe030cb --- /dev/null +++ b/sample-project/res/HelloCordova-Release.entitlements @@ -0,0 +1,17 @@ + + + + + aps-environment + production + com.apple.security.application-groups + + group.com.braze.hellocordova.PushStories + + com.apple.developer.associated-domains + + applinks:universal.braze.com + applinks:universal.example.com + + + diff --git a/sample-project/www/js/index.js b/sample-project/www/js/index.js index 29a46d0..2886384 100755 --- a/sample-project/www/js/index.js +++ b/sample-project/www/js/index.js @@ -116,7 +116,16 @@ function setSdkAuthenticationSignature() { async function getFeatureFlag() { try { - const featureFlag = await BrazePlugin.getFeatureFlag(document.getElementById("featureFlagInputId").value); + const featureFlagId = document.getElementById("featureFlagInputId").value; + if (!featureFlagId) { + showTextBubble('Feature Flag ID not entered.'); + return; + } + const featureFlag = await BrazePlugin.getFeatureFlag(featureFlagId); + if (!featureFlag) { + showTextBubble(`No Feature Flag found for ID: ${featureFlagId}`); + return; + } showTextBubble(`Feature Flag: ${JSON.stringify(featureFlag)}`); } catch (error) { // This method can error out if the Feature Flag fails to serialize at the native layer. diff --git a/src/android/BrazePlugin.kt b/src/android/BrazePlugin.kt index 27aad7d..eb5f924 100644 --- a/src/android/BrazePlugin.kt +++ b/src/android/BrazePlugin.kt @@ -72,7 +72,7 @@ open class BrazePlugin : CordovaPlugin() { disableAutoStartSessions = false return true } - "registerAppboyPushMessages", "setRegisteredPushToken" -> { + "setRegisteredPushToken" -> { runOnBraze { it.registeredPushToken = args.getString(0) } return true } @@ -293,7 +293,14 @@ open class BrazePlugin : CordovaPlugin() { return true } "getFeatureFlag" -> { - callbackContext.success(Braze.getInstance(applicationContext).getFeatureFlag(args.getString(0)).forJsonPut()) + runOnBraze { + val result = it.getFeatureFlag(args.getString(0)) + if (result == null) { + callbackContext.sendCordovaSuccessPluginResultAsNull() + } else { + callbackContext.sendPluginResult(PluginResult(PluginResult.Status.OK, result.forJsonPut())) + } + } return true } "getAllFeatureFlags" -> { @@ -322,7 +329,7 @@ open class BrazePlugin : CordovaPlugin() { runOnBraze { val flagId = args.getString(0) val propKey = args.getString(1) - val result = it.getFeatureFlag(flagId).getBooleanProperty(propKey) + val result = it.getFeatureFlag(flagId)?.getBooleanProperty(propKey) if (result == null) { callbackContext.sendCordovaSuccessPluginResultAsNull() } else { @@ -335,7 +342,7 @@ open class BrazePlugin : CordovaPlugin() { runOnBraze { val flagId = args.getString(0) val propKey = args.getString(1) - val result = it.getFeatureFlag(flagId).getStringProperty(propKey) + val result = it.getFeatureFlag(flagId)?.getStringProperty(propKey) if (result == null) { callbackContext.sendCordovaSuccessPluginResultAsNull() } else { @@ -348,7 +355,7 @@ open class BrazePlugin : CordovaPlugin() { runOnBraze { val flagId = args.getString(0) val propKey = args.getString(1) - val result = it.getFeatureFlag(flagId).getNumberProperty(propKey) + val result = it.getFeatureFlag(flagId)?.getNumberProperty(propKey) if (result == null) { callbackContext.sendCordovaSuccessPluginResultAsNull() } else { @@ -504,6 +511,9 @@ open class BrazePlugin : CordovaPlugin() { if (cordovaPreferences.contains(SDK_AUTH_ENABLED_PREFERENCE)) { configBuilder.setIsSdkAuthenticationEnabled(cordovaPreferences.getBoolean(SDK_AUTH_ENABLED_PREFERENCE, false)) } + if (cordovaPreferences.contains(TRIGGER_ACTION_MINIMUM_TIME_INTERVAL_SECONDS_PREFERENCE)) { + configBuilder.setTriggerActionMinimumTimeIntervalSeconds(parseNumericPreferenceAsInteger(cordovaPreferences.getString(TRIGGER_ACTION_MINIMUM_TIME_INTERVAL_SECONDS_PREFERENCE, "30"))) + } Braze.configure(applicationContext, configBuilder.build()) } @@ -650,6 +660,7 @@ open class BrazePlugin : CordovaPlugin() { private const val ENABLE_GEOFENCES_PREFERENCE = "com.braze.geofences_enabled" private const val DISABLE_AUTO_START_SESSIONS_PREFERENCE = "com.braze.android_disable_auto_session_tracking" private const val SDK_AUTH_ENABLED_PREFERENCE = "com.braze.sdk_authentication_enabled" + private const val TRIGGER_ACTION_MINIMUM_TIME_INTERVAL_SECONDS_PREFERENCE = "com.braze.trigger_action_minimum_time_interval_seconds" /** * When applied, restricts the SDK from taking diff --git a/src/android/ContentCardUtils.kt b/src/android/ContentCardUtils.kt index 4eadffa..e06cb2a 100644 --- a/src/android/ContentCardUtils.kt +++ b/src/android/ContentCardUtils.kt @@ -43,7 +43,7 @@ object ContentCardUtils { put("extras", JSONObject(card.extras)) } when (card.cardType) { - BANNER -> mapBannerImageCardFields(mappedCardJson, card as BannerImageCard) + IMAGE -> mapImageOnlyCardFields(mappedCardJson, card as ImageOnlyCard) CAPTIONED_IMAGE -> mapCaptionedImageCardFields(mappedCardJson, card as CaptionedImageCard) SHORT_NEWS -> mapShortNewsCardFields(mappedCardJson, card as ShortNewsCard) TEXT_ANNOUNCEMENT -> mapTextAnnouncementCardFields(mappedCardJson, card as TextAnnouncementCard) @@ -82,12 +82,12 @@ object ContentCardUtils { } } - private fun mapBannerImageCardFields(mappedCard: JSONObject, card: BannerImageCard) { + private fun mapImageOnlyCardFields(mappedCard: JSONObject, card: ImageOnlyCard) { mappedCard.apply { put("image", card.imageUrl) put("imageAspectRatio", card.aspectRatio.toDouble()) put("domain", card.domain) - put("type", "Banner") + put("type", "ImageOnly") } } } diff --git a/src/android/build-extras.gradle b/src/android/build-extras.gradle index 421d67d..7e8529b 100644 --- a/src/android/build-extras.gradle +++ b/src/android/build-extras.gradle @@ -4,7 +4,7 @@ repositories { } dependencies { - implementation 'com.braze:android-sdk-ui:27.0.1' + implementation 'com.braze:android-sdk-ui:30.0.0' implementation 'com.google.firebase:firebase-messaging:23.0.0' } diff --git a/src/ios/BrazePlugin.m b/src/ios/BrazePlugin.m index fb7cd8d..f6b3552 100644 --- a/src/ios/BrazePlugin.m +++ b/src/ios/BrazePlugin.m @@ -18,6 +18,9 @@ @interface BrazePlugin() @property NSString *sessionTimeout; @property NSString *enableSDKAuth; @property NSString *sdkAuthCallbackID; + @property NSString *triggerActionMinimumTimeInterval; + @property NSString *pushAppGroup; + @property NSString *forwardUniversalLinks; @end static Braze *_braze; @@ -44,6 +47,9 @@ - (void)pluginInitialize { self.disableUNAuthorizationOptionProvisional = settings[@"com.braze.ios_disable_un_authorization_option_provisional"]; self.sessionTimeout = settings[@"com.braze.ios_session_timeout"]; self.enableSDKAuth = settings[@"com.braze.sdk_authentication_enabled"]; + self.triggerActionMinimumTimeInterval = settings[@"com.braze.trigger_action_minimum_time_interval_seconds"]; + self.pushAppGroup = settings[@"com.braze.ios_push_app_group"]; + self.forwardUniversalLinks = settings[@"com.braze.ios_forward_universal_links"]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishLaunchingListener:) name:UIApplicationDidFinishLaunchingNotification object:nil]; @@ -61,10 +67,29 @@ - (void)didFinishLaunchingListener:(NSNotification *)notification { [configuration.location setGeofencesEnabled:self.enableGeofences]; [configuration.location setAutomaticLocationCollection:self.enableLocationCollection]; + // Set the minimum time interval between triggers (in seconds) + if ([self isStringPositiveNumeric:self.triggerActionMinimumTimeInterval]) { + NSTimeInterval intervalCast = [self.triggerActionMinimumTimeInterval doubleValue]; + configuration.triggerMinimumTimeInterval = intervalCast; + NSLog(@"Setting \"trigger_action_minimum_time_interval_seconds\" to: %g", intervalCast); + } else { + NSLog(@"\"trigger_action_minimum_time_interval_seconds\" value not valid. Setting value to 30."); + } + + // Set if the SDK should automatically recognize and forward universal links to the system methods + if ([self.forwardUniversalLinks isEqualToString:@"YES"]) { + configuration.forwardUniversalLinks = @YES; + NSLog(@"iOS universal link forwarding is enabled."); + } + // Set the time interval for session time out (in seconds) NSNumber *timeout = [[[NSNumberFormatter alloc] init] numberFromString:self.sessionTimeout]; [configuration setSessionTimeout:[timeout doubleValue]]; [configuration.api addSDKMetadata:@[[BRZSDKMetadata cordova]]]; + + // Set the app group identifier for push stories. + [configuration.push setAppGroup:self.pushAppGroup]; + self.braze = [[Braze alloc] initWithConfiguration:configuration]; self.braze.inAppMessagePresenter = [[BrazeInAppMessageUI alloc] init]; self.subscriptions = [NSMutableArray array]; @@ -633,10 +658,10 @@ + (NSDictionary *)formattedContentCard:(BRZContentCardRaw *)card { formattedContentCardData[@"domain"] = card.domain ?: [NSNull null]; formattedContentCardData[@"type"] = @"Classic"; break; - case BRZContentCardRawTypeBanner: + case BRZContentCardRawTypeImageOnly: formattedContentCardData[@"image"] = [card.image absoluteString]; formattedContentCardData[@"imageAspectRatio"] = @(card.imageAspectRatio); - formattedContentCardData[@"type"] = @"Banner"; + formattedContentCardData[@"type"] = @"ImageOnly"; break; case BRZContentCardRawTypeCaptionedImage: formattedContentCardData[@"image"] = [card.image absoluteString]; @@ -671,7 +696,10 @@ + (NSString *)getJsonFromExtras:(NSDictionary *)extras { - (void)getFeatureFlag:(CDVInvokedUrlCommand *)command { NSString *featureFlagId = [command argumentAtIndex:0 withDefault:nil]; BRZFeatureFlag *featureFlag = [self.braze.featureFlags featureFlagWithId:featureFlagId]; - + if (featureFlag == nil) { + [self sendCordovaSuccessPluginResultAsNull:command]; + return; + } NSError* error = nil; id flagJSON = [NSJSONSerialization JSONObjectWithData:[featureFlag json] options:NSJSONReadingMutableContainers @@ -706,6 +734,11 @@ - (void)getFeatureFlagBooleanProperty:(CDVInvokedUrlCommand *)command { NSString *propertyKey = [command argumentAtIndex:1 withDefault:nil]; BRZFeatureFlag *featureFlag = [self.braze.featureFlags featureFlagWithId:featureFlagId]; + if (!featureFlag) { + [self sendCordovaSuccessPluginResultAsNull:command]; + return; + } + NSNumber *boolProperty = [featureFlag boolPropertyForKey:propertyKey]; if (boolProperty) { [self sendCordovaSuccessPluginResultWithBool:boolProperty andCommand:command]; @@ -719,6 +752,11 @@ - (void)getFeatureFlagStringProperty:(CDVInvokedUrlCommand *)command { NSString *propertyKey = [command argumentAtIndex:1 withDefault:nil]; BRZFeatureFlag *featureFlag = [self.braze.featureFlags featureFlagWithId:featureFlagId]; + if (!featureFlag) { + [self sendCordovaSuccessPluginResultAsNull:command]; + return; + } + NSString *stringProperty = [featureFlag stringPropertyForKey:propertyKey]; if (stringProperty) { [self sendCordovaSuccessPluginResultWithString:stringProperty andCommand:command]; @@ -732,6 +770,11 @@ - (void)getFeatureFlagNumberProperty:(CDVInvokedUrlCommand *)command { NSString *propertyKey = [command argumentAtIndex:1 withDefault:nil]; BRZFeatureFlag *featureFlag = [self.braze.featureFlags featureFlagWithId:featureFlagId]; + if (!featureFlag) { + [self sendCordovaSuccessPluginResultAsNull:command]; + return; + } + NSNumber *numberProperty = [featureFlag numberPropertyForKey:propertyKey]; if (numberProperty) { [self sendCordovaSuccessPluginResultWithDouble:[numberProperty doubleValue] andCommand:command]; @@ -831,4 +874,20 @@ - (void)sendCordovaSuccessPluginResultAsNull:(CDVInvokedUrlCommand *)command { [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } +// MARK: - Helper Methods +/** +* Takes an input NSString and returns true if it is a valid positive number. +* If the string is not a valid number or is negative, returns false. +**/ +- (BOOL)isStringPositiveNumeric:(NSString *)inputString { + if ([inputString length] > 0) { + // Check if the string is a valid number (only contains digits 0 through 9) + NSCharacterSet* notDigits = [[NSCharacterSet decimalDigitCharacterSet] invertedSet]; + if (([inputString rangeOfCharacterFromSet:notDigits].location == NSNotFound) && [inputString doubleValue] >= 0) { + return true; + } + } + return false; +} + @end diff --git a/www/BrazePlugin.js b/www/BrazePlugin.js index d9366d4..3d08d55 100644 --- a/www/BrazePlugin.js +++ b/www/BrazePlugin.js @@ -40,17 +40,6 @@ BrazePlugin.prototype.changeUser = function (userId, sdkAuthenticationToken) { cordova.exec(null, null, "BrazePlugin", "changeUser", [userId, sdkAuthenticationToken]); } -/** -* ** ANDROID ONLY** -* -* Registers the device as eligible to receive push notifications from Braze. -* -* @param {string} registrationId - The registration ID / push token. -*/ -BrazePlugin.prototype.registerAppboyPushMessages = function (registrationID) { - cordova.exec(null, null, "BrazePlugin", "registerAppboyPushMessages", [registrationID]); -} - /** * ** ANDROID ONLY** * @@ -450,9 +439,7 @@ BrazePlugin.prototype.getDeviceId = function (successCallback, errorCallback) { * not force a refresh. * * @param id The ID of the Feature Flag to retrieve. - * @return A promise containing the [FeatureFlag] of the requested ID. - * If the Feature Flag does not exist, a [FeatureFlag] will be returned with - * enabled set to `false` and empty properties. + * @return A promise containing the [FeatureFlag] of the requested ID, or null if the Feature Flag does not exist. */ BrazePlugin.prototype.getFeatureFlag = function (id) { return new Promise((resolve, reject) => { @@ -500,7 +487,7 @@ BrazePlugin.prototype.subscribeToFeatureFlagsUpdates = function (flagId, propert * @param {string} flagId - The identifier for the Feature Flag. * @param {string} propertyKey - The key for the boolean property. * - * @return A promise containing the boolean property requested. This should return null if there is no such property. + * @return A promise containing the boolean property requested. This will return null if there is no such property or Feature Flag. */ BrazePlugin.prototype.getFeatureFlagBooleanProperty = function(flagId, propertyKey) { return new Promise((resolve, reject) => { @@ -517,7 +504,7 @@ BrazePlugin.prototype.getFeatureFlagBooleanProperty = function(flagId, propertyK * @param {string} flagId - The identifier for the Feature Flag. * @param {string} propertyKey - The key for the string property. * - * @return A promise containing the string property requested. This should return null if there is no such property. + * @return A promise containing the string property requested. This will return null if there is no such property or Feature Flag. */ BrazePlugin.prototype.getFeatureFlagStringProperty = function(flagId, propertyKey) { return new Promise((resolve, reject) => { @@ -534,7 +521,7 @@ BrazePlugin.prototype.getFeatureFlagStringProperty = function(flagId, propertyKe * @param {string} flagId - The identifier for the Feature Flag. * @param {string} propertyKey - The key for the number property. * - * @return A promise containing the number property requested. This should return null if there is no such property. + * @return A promise containing the number property requested. This will return null if there is no such property or Feature Flag. */ BrazePlugin.prototype.getFeatureFlagNumberProperty = function(flagId, propertyKey) { return new Promise((resolve, reject) => { @@ -589,7 +576,7 @@ BrazePlugin.prototype['CardCategories'] = { BrazePlugin.prototype['ContentCardTypes'] = { 'CLASSIC': 'Classic', - 'BANNER': 'Banner', + 'IMAGE_ONLY': 'ImageOnly', 'CAPTIONED': 'Captioned' };