diff --git a/.scripts/changes.md b/.scripts/changes.md index f617539..c086074 100644 --- a/.scripts/changes.md +++ b/.scripts/changes.md @@ -1,2 +1,2 @@ -- Apptentive Android SDK: 6.8.0 -- Apptentive iOS SDK: 6.8.1 +- Apptentive Android SDK: 6.9.0 +- Apptentive iOS SDK: 6.9.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 488dc77..a9d68e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ This document lets you know what has changed in the Cordova plugin. For changes - [Android Changelog](https://github.com/apptentive/apptentive-kit-android/blob/master/CHANGELOG.md) - [iOS Changelog](https://github.com/apptentive/apptentive-kit-ios/blob/master/CHANGELOG.md) +# 2024-10-03 - v6.9.0 + +- Apptentive Android SDK: 6.9.0 +- Apptentive iOS SDK: 6.9.0 + # 2024-06-26 - v6.8.0 - Apptentive Android SDK: 6.8.0 diff --git a/package.json b/package.json index fd9ddc4..1d9fe80 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "apptentive-cordova", - "version": "6.8.0", + "version": "6.9.0", "description": "Apptentive Plugin For Cordova", "cordova": { "id": "apptentive-cordova", diff --git a/plugin.xml b/plugin.xml index 40cb6cc..3ef8061 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + Apptentive Apptentive Plugin For Cordova @@ -54,7 +54,7 @@ - + @@ -112,7 +112,7 @@ - + diff --git a/src/android/ApptentiveBridge.kt b/src/android/ApptentiveBridge.kt index cc42d1d..c1f703c 100644 --- a/src/android/ApptentiveBridge.kt +++ b/src/android/ApptentiveBridge.kt @@ -242,6 +242,16 @@ class ApptentiveBridge : CordovaPlugin(), ApptentiveActivityInfo { } return true } + ACTION_SET_PUSH_NOTIFICATION_INTEGRATION -> { + if (isApptentiveRegistered) { + val provider = parsePushProvider("apptentive") + android.util.Log.d("Apptentive", "[CORDOVA] Provider is set to $provider") + val token = args.getString(0) + Apptentive.setPushNotificationIntegration(currentActivity.application, provider, token) + } else + android.util.Log.d("Apptentive", "[CORDOVA] Apptentive is not registered, push notification is not integerated") + return true + } else -> { android.util.Log.e("Apptentive", "[CORDOVA] Unhandled action in ApptentiveBridge: $action") callbackContext.error("Unhandled action in ApptentiveBridge: $action") @@ -328,6 +338,16 @@ class ApptentiveBridge : CordovaPlugin(), ApptentiveActivityInfo { } } + private fun parsePushProvider(pushProvider: String): Int { + when { + pushProvider.contains("apptentive") -> { return Apptentive.PUSH_PROVIDER_APPTENTIVE } + pushProvider.contains("amazon") -> { return Apptentive.PUSH_PROVIDER_AMAZON_AWS_SNS } + pushProvider.contains("parse") -> { return Apptentive.PUSH_PROVIDER_PARSE } + pushProvider.contains("urban_airship") -> { return Apptentive.PUSH_PROVIDER_URBAN_AIRSHIP } + else -> throw IllegalArgumentException("Unknown push provider: $pushProvider") + } + } + private companion object { val CORDOVA_TAG = LogTag("CORDOVA") @@ -360,6 +380,7 @@ class ApptentiveBridge : CordovaPlugin(), ApptentiveActivityInfo { const val ACTION_SHOW_MESSAGE_CENTER = "showMessageCenter" const val ACTION_CAN_SHOW_MESSAGE_CENTER = "canShowMessageCenter" const val ACTION_CAN_SHOW_INTERACTION = "canShowInteraction" + const val ACTION_SET_PUSH_NOTIFICATION_INTEGRATION = "setPushNotificationIntegration" } override fun getApptentiveActivityInfo(): Activity? { diff --git a/src/ios/ApptentiveBridge.swift b/src/ios/ApptentiveBridge.swift index b80841c..4d7abf9 100644 --- a/src/ios/ApptentiveBridge.swift +++ b/src/ios/ApptentiveBridge.swift @@ -231,6 +231,20 @@ class ApptentiveBridge: CDVPlugin { } } + @objc func setPushNotificationIntegration(_ command: CDVInvokedUrlCommand) { + do { + let _ = try Self.checkArgumentCount(command, 1...1) + let tokenString = try Self.string(from: command) + guard let tokenData = Data(hexString: tokenString) else { + throw PluginError.invalidTokenString(tokenString) + } + Apptentive.shared.setRemoteNotificationDeviceToken(tokenData) + self.commandDelegate.send(.init(status: CDVCommandStatus_OK), callbackId: command.callbackId) + } catch let error { + self.commandDelegate.send(.init(status: CDVCommandStatus_ERROR, messageAs: error.localizedDescription), callbackId: command.callbackId) + } + } + // MARK: - Helper functions func sendUnimplementedError(_ command: CDVInvokedUrlCommand) { @@ -376,6 +390,7 @@ class ApptentiveBridge: CDVPlugin { case invalidArgumentType(atIndex: Int, expecting: String) case unimplementedCommand(String) case invalidJSONData + case invalidTokenString(String) case unrecognizedLogLevel(String) var errorDescription: String? { @@ -416,9 +431,39 @@ class ApptentiveBridge: CDVPlugin { case .invalidJSONData: return "The string passed for the custom data argument is not valid JSON." + case .invalidTokenString(let string): + return "The device token (\(string)) was not recognized as valid hex-encoded data." + case .unrecognizedLogLevel(let logLevel): return "The log level (\"\(logLevel)\") is not a valid log level (valid values are \"verbose\", \"debug\", \"info\", \"warn\", \"error\", and \"critical\")." } } } } + +extension Data { + /// Creates a new Data object by converting hexadecimal characters in the input string. + /// + /// Returns nil if the string contains non-hexadecimal characters or has an odd number of characters. + /// - Parameter hexString: A string of hexadecimal characters. + init?(hexString: String) { + var result = Data() + var index = hexString.startIndex + + while index < hexString.endIndex { + guard let endIndex = hexString.index(index, offsetBy: 2, limitedBy: hexString.endIndex) else { + return nil + } + + guard let byte = UInt8(String(hexString[index..