Skip to content

Commit

Permalink
Merge pull request #124 from apptentive/develop
Browse files Browse the repository at this point in the history
6.9.0 Release
  • Loading branch information
PoornimaApptentive authored Oct 16, 2024
2 parents 3e85dca + 2fa82cd commit 326359b
Show file tree
Hide file tree
Showing 7 changed files with 318 additions and 109 deletions.
4 changes: 2 additions & 2 deletions .scripts/changes.md
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apptentive-cordova",
"version": "6.8.0",
"version": "6.9.0",
"description": "Apptentive Plugin For Cordova",
"cordova": {
"id": "apptentive-cordova",
Expand Down
6 changes: 3 additions & 3 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="apptentive-cordova" version="6.8.0">
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="apptentive-cordova" version="6.9.0">

<name>Apptentive</name>
<description>Apptentive Plugin For Cordova</description>
Expand Down Expand Up @@ -54,7 +54,7 @@
<meta-data android:name="apptentive_rating_interaction_throttle_length" android:value="$ANDROID_RATING_INTERACTION_THROTTLE_LENGTH"/>
</config-file>

<framework src="com.apptentive:apptentive-kit-android:6.8.0"/>
<framework src="com.apptentive:apptentive-kit-android:6.9.0"/>
<source-file src="src/android/ApptentiveBridge.kt" target-dir="app/src/main/kotlin/com/apptentive/cordova"/>
<source-file src="src/android/JsonHelper.kt" target-dir="app/src/main/kotlin/com/apptentive/cordova"/>
<source-file src="src/android/Util.kt" target-dir="app/src/main/kotlin/com/apptentive/cordova"/>
Expand Down Expand Up @@ -112,7 +112,7 @@
<source url="https://github.com/CocoaPods/Specs.git"/>
</config>
<pods use-frameworks="true">
<pod name="ApptentiveKit" spec="~&gt; 6.8.1" swift-version="5"/>
<pod name="ApptentiveKit" spec="~&gt; 6.9.0" swift-version="5"/>
</pods>
</podspec>
</platform>
Expand Down
21 changes: 21 additions & 0 deletions src/android/ApptentiveBridge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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? {
Expand Down
45 changes: 45 additions & 0 deletions src/ios/ApptentiveBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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? {
Expand Down Expand Up @@ -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..<endIndex]), radix: 16) else {
return nil
}

result.append(byte)

index = endIndex
}

self = result
}
}
Loading

0 comments on commit 326359b

Please sign in to comment.