From 0ca6b5c7fed72f4339bacc0506008adbf51c2d73 Mon Sep 17 00:00:00 2001 From: Mirzamehdi Date: Sun, 28 Apr 2024 13:32:31 +0200 Subject: [PATCH 1/3] Implementation of syncPurchases function --- README.md | 1 + .../kmprevenuecat/purchases/PurchasesImpl.kt | 15 ++++++++ .../mmk/kmprevenuecat/purchases/Purchases.kt | 2 +- .../purchases/coroutinesExtensions.kt | 15 ++++++++ .../kmprevenuecat/purchases/PurchasesImpl.kt | 38 ++++++++++--------- 5 files changed, 53 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 4a30e01..f2b31ec 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ fun setAttributes(attributes: Map) fun setFirebaseAppInstanceID(firebaseAppInstanceID: String) fun collectDeviceIdentifiers() fun enableAdServicesAttributionTokenCollection() +fun syncPurchases(onResult: (Result) -> Unit) ``` ### Purchases-UI diff --git a/kmprevenuecat-purchases/src/androidMain/kotlin/com/mmk/kmprevenuecat/purchases/PurchasesImpl.kt b/kmprevenuecat-purchases/src/androidMain/kotlin/com/mmk/kmprevenuecat/purchases/PurchasesImpl.kt index c1de39c..3cb08c4 100644 --- a/kmprevenuecat-purchases/src/androidMain/kotlin/com/mmk/kmprevenuecat/purchases/PurchasesImpl.kt +++ b/kmprevenuecat-purchases/src/androidMain/kotlin/com/mmk/kmprevenuecat/purchases/PurchasesImpl.kt @@ -5,7 +5,10 @@ import com.mmk.kmprevenuecat.purchases.data.CustomerInfo import com.mmk.kmprevenuecat.purchases.data.LogInResult import com.revenuecat.purchases.PurchasesConfiguration import com.revenuecat.purchases.PurchasesError +import com.revenuecat.purchases.awaitSyncPurchases import com.revenuecat.purchases.interfaces.ReceiveCustomerInfoCallback +import com.revenuecat.purchases.interfaces.SyncPurchasesCallback +import com.revenuecat.purchases.syncPurchasesWith import com.revenuecat.purchases.CustomerInfo as RevenueCatCustomerInfo import com.revenuecat.purchases.Purchases as RevenueCatPurchases import com.revenuecat.purchases.interfaces.LogInCallback as RevenueCatLoginCallback @@ -83,4 +86,16 @@ internal class PurchasesImpl(private val context: Context) : Purchases { } override fun enableAdServicesAttributionTokenCollection() = Unit + @OptIn(KMPRevenueCatInternalApi::class) + override fun syncPurchases(onResult: (Result) -> Unit) { + RevenueCatPurchases.sharedInstance.syncPurchases(object:SyncPurchasesCallback{ + override fun onError(error: PurchasesError) { + onResult(Result.failure(Exception(error.message))) + } + + override fun onSuccess(customerInfo: com.revenuecat.purchases.CustomerInfo) { + onResult(Result.success(customerInfo.asCustomerInfo())) + } + }) + } } \ No newline at end of file diff --git a/kmprevenuecat-purchases/src/commonMain/kotlin/com/mmk/kmprevenuecat/purchases/Purchases.kt b/kmprevenuecat-purchases/src/commonMain/kotlin/com/mmk/kmprevenuecat/purchases/Purchases.kt index 1275172..9590b28 100644 --- a/kmprevenuecat-purchases/src/commonMain/kotlin/com/mmk/kmprevenuecat/purchases/Purchases.kt +++ b/kmprevenuecat-purchases/src/commonMain/kotlin/com/mmk/kmprevenuecat/purchases/Purchases.kt @@ -37,5 +37,5 @@ public interface Purchases { public fun setFirebaseAppInstanceID(firebaseAppInstanceID: String) public fun collectDeviceIdentifiers() public fun enableAdServicesAttributionTokenCollection() - + public fun syncPurchases(onResult: (Result) -> Unit) } diff --git a/kmprevenuecat-purchases/src/commonMain/kotlin/com/mmk/kmprevenuecat/purchases/coroutinesExtensions.kt b/kmprevenuecat-purchases/src/commonMain/kotlin/com/mmk/kmprevenuecat/purchases/coroutinesExtensions.kt index 2853966..a86f107 100644 --- a/kmprevenuecat-purchases/src/commonMain/kotlin/com/mmk/kmprevenuecat/purchases/coroutinesExtensions.kt +++ b/kmprevenuecat-purchases/src/commonMain/kotlin/com/mmk/kmprevenuecat/purchases/coroutinesExtensions.kt @@ -23,3 +23,18 @@ public suspend fun Purchases.awaitCustomerInfo(fetchPolicy: CacheFetchPolicy=Cac ) } } + +/** + * @throws [PurchasesException] if there's an error retrieving the customer info. + * + */ +public suspend fun Purchases.awaitSyncPurchases(): CustomerInfo { + return suspendCoroutine { continuation -> + syncPurchases( + onResult = {result -> + if (result.isSuccess && result.getOrNull() != null) continuation.resume(result.getOrNull()!!) + else continuation.resumeWithException(PurchasesException(result.exceptionOrNull()?.message)) + }, + ) + } +} diff --git a/kmprevenuecat-purchases/src/iosMain/kotlin/com/mmk/kmprevenuecat/purchases/PurchasesImpl.kt b/kmprevenuecat-purchases/src/iosMain/kotlin/com/mmk/kmprevenuecat/purchases/PurchasesImpl.kt index 03cde0e..e620360 100644 --- a/kmprevenuecat-purchases/src/iosMain/kotlin/com/mmk/kmprevenuecat/purchases/PurchasesImpl.kt +++ b/kmprevenuecat-purchases/src/iosMain/kotlin/com/mmk/kmprevenuecat/purchases/PurchasesImpl.kt @@ -1,11 +1,13 @@ package com.mmk.kmprevenuecat.purchases +import cocoapods.RevenueCat.RCCustomerInfo import cocoapods.RevenueCat.RCPurchases import cocoapods.RevenueCat.configureWithAPIKey import cocoapods.RevenueCat.enableAdServicesAttributionTokenCollection import com.mmk.kmprevenuecat.purchases.data.CustomerInfo import com.mmk.kmprevenuecat.purchases.data.LogInResult import kotlinx.cinterop.ExperimentalForeignApi +import platform.Foundation.NSError @OptIn(ExperimentalForeignApi::class) @@ -37,15 +39,9 @@ internal class PurchasesImpl : Purchases { }) } - @OptIn(KMPRevenueCatInternalApi::class) + override fun logOut(onResult: (Result) -> Unit) { - RCPurchases.sharedPurchases().logOutWithCompletion { rcCustomerInfo, nsError -> - if (rcCustomerInfo != null) onResult( - Result.success(rcCustomerInfo.asCustomerInfo()) - ) - else - onResult(Result.failure(Exception(nsError?.localizedFailureReason))) - } + RCPurchases.sharedPurchases().logOutWithCompletion(onCompletionHandler(onResult)) } override fun getCustomerInfo( @@ -54,23 +50,18 @@ internal class PurchasesImpl : Purchases { ) { RCPurchases.sharedPurchases().getCustomerInfoWithFetchPolicy( fetchPolicy = fetchPolicy.asRevenueCatCacheFetchPolicy(), - completion = { rcCustomerInfo, nsError -> - if (rcCustomerInfo != null) onResult( - Result.success(rcCustomerInfo.asCustomerInfo()) - ) - else - onResult(Result.failure(Exception(nsError?.localizedFailureReason))) - }) + completion = onCompletionHandler(onResult) + ) } - override fun setAttributes(attributes: Map){ + override fun setAttributes(attributes: Map) { val map = attributes.map { (key, value) -> key as Any? to value as Any? }.toMap() RCPurchases.sharedPurchases().setAttributes(map) } - override fun setFirebaseAppInstanceID(firebaseAppInstanceID: String){ + override fun setFirebaseAppInstanceID(firebaseAppInstanceID: String) { RCPurchases.sharedPurchases().setFirebaseAppInstanceID(firebaseAppInstanceID) } @@ -82,4 +73,17 @@ internal class PurchasesImpl : Purchases { RCPurchases.sharedPurchases().attribution().enableAdServicesAttributionTokenCollection() } + override fun syncPurchases(onResult: (Result) -> Unit) { + RCPurchases.sharedPurchases() + .syncPurchasesWithCompletion(completion = onCompletionHandler(onResult)) + } + + @OptIn(KMPRevenueCatInternalApi::class) + private fun onCompletionHandler(onResult: (Result) -> Unit): ((RCCustomerInfo?, NSError?) -> Unit) { + return { rcCustomerInfo, nsError -> + if (rcCustomerInfo != null) onResult(Result.success(rcCustomerInfo.asCustomerInfo())) + else onResult(Result.failure(Exception(nsError?.localizedFailureReason))) + } + } + } \ No newline at end of file From 5a07c21781e41d30b9e9be86f2f5dec787db37de Mon Sep 17 00:00:00 2001 From: Mirzamehdi Date: Sun, 28 Apr 2024 14:16:21 +0200 Subject: [PATCH 2/3] Bumping revenue cat versions: android 7.9.0, ios: 4.41.1 --- README.md | 2 +- gradle/libs.versions.toml | 4 +- .../kmprevenuecat_purchases_ui.podspec | 4 +- .../mmk/kmprevenuecat/purchases/ui/Paywall.kt | 3 +- .../kmprevenuecat_purchases.podspec | 2 +- .../iosApp/iosApp.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/swiftpm/Package.resolved | 40 +++++++++---------- 7 files changed, 29 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index f2b31ec..c80c2e4 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Related Blog Post (if you want to integrate it yourself without this library): h - **iOS:** `minDeploymentTarget 15.0` - **RevenueCat Android version:** `7.5.2` -- **RevenueCat iOS version:** `4.39.0` +- **RevenueCat iOS version:** `4.41.1` ### Gradle Setup KMPRevenueCat is available on Maven Central. In your root project `build.gradle.kts` file (or `settings.gradle` file) add `mavenCentral()` to repositories. diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 568ac3b..74fb1f0 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -20,8 +20,8 @@ koin = "3.5.4" kotlinx-binary-validator = "0.13.2" dokka = "1.9.20" koinCompose = "1.1.0" -revenueCatAndroid="7.5.2" -revenueCatIos="4.39.0" +revenueCatAndroid="7.9.0" +revenueCatIos="4.41.1" diff --git a/kmprevenuecat-purchases-ui/kmprevenuecat_purchases_ui.podspec b/kmprevenuecat-purchases-ui/kmprevenuecat_purchases_ui.podspec index 3e822f1..3254885 100644 --- a/kmprevenuecat-purchases-ui/kmprevenuecat_purchases_ui.podspec +++ b/kmprevenuecat-purchases-ui/kmprevenuecat_purchases_ui.podspec @@ -9,8 +9,8 @@ Pod::Spec.new do |spec| spec.vendored_frameworks = 'build/cocoapods/framework/KMPRevenueCatPurchasesUI.framework' spec.libraries = 'c++' spec.ios.deployment_target = '15.0' - spec.dependency 'RevenueCat', '4.39.0' - spec.dependency 'RevenueCatUI', '4.39.0' + spec.dependency 'RevenueCat', '4.41.1' + spec.dependency 'RevenueCatUI', '4.41.1' if !Dir.exist?('build/cocoapods/framework/KMPRevenueCatPurchasesUI.framework') || Dir.empty?('build/cocoapods/framework/KMPRevenueCatPurchasesUI.framework') raise " diff --git a/kmprevenuecat-purchases-ui/src/iosMain/kotlin/com/mmk/kmprevenuecat/purchases/ui/Paywall.kt b/kmprevenuecat-purchases-ui/src/iosMain/kotlin/com/mmk/kmprevenuecat/purchases/ui/Paywall.kt index 2a6bdbc..c3ddce9 100644 --- a/kmprevenuecat-purchases-ui/src/iosMain/kotlin/com/mmk/kmprevenuecat/purchases/ui/Paywall.kt +++ b/kmprevenuecat-purchases-ui/src/iosMain/kotlin/com/mmk/kmprevenuecat/purchases/ui/Paywall.kt @@ -18,7 +18,8 @@ public actual fun Paywall( RCPaywallViewController( offering = null, displayCloseButton = shouldDisplayDismissButton, - dismissRequestedHandler = null + dismissRequestedHandler = null, + shouldBlockTouchEvents = false ).apply { updateWithDisplayCloseButton(shouldDisplayDismissButton) setDelegate(listener?.asRCPaywallViewControllerDelegate(onDismiss)) diff --git a/kmprevenuecat-purchases/kmprevenuecat_purchases.podspec b/kmprevenuecat-purchases/kmprevenuecat_purchases.podspec index 990bc23..3eb9f41 100644 --- a/kmprevenuecat-purchases/kmprevenuecat_purchases.podspec +++ b/kmprevenuecat-purchases/kmprevenuecat_purchases.podspec @@ -9,7 +9,7 @@ Pod::Spec.new do |spec| spec.vendored_frameworks = 'build/cocoapods/framework/KMPRevenueCatPurchases.framework' spec.libraries = 'c++' spec.ios.deployment_target = '15.0' - spec.dependency 'RevenueCat', '4.39.0' + spec.dependency 'RevenueCat', '4.41.1' if !Dir.exist?('build/cocoapods/framework/KMPRevenueCatPurchases.framework') || Dir.empty?('build/cocoapods/framework/KMPRevenueCatPurchases.framework') raise " diff --git a/sampleApp/iosApp/iosApp.xcodeproj/project.pbxproj b/sampleApp/iosApp/iosApp.xcodeproj/project.pbxproj index 89e68ff..4c5f51f 100644 --- a/sampleApp/iosApp/iosApp.xcodeproj/project.pbxproj +++ b/sampleApp/iosApp/iosApp.xcodeproj/project.pbxproj @@ -428,7 +428,7 @@ repositoryURL = "https://github.com/RevenueCat/purchases-ios"; requirement = { kind = exactVersion; - version = 4.39.0; + version = 4.41.1; }; }; /* End XCRemoteSwiftPackageReference section */ diff --git a/sampleApp/iosApp/iosApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/sampleApp/iosApp/iosApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index a41d71c..f7e8ebc 100644 --- a/sampleApp/iosApp/iosApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/sampleApp/iosApp/iosApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -5,8 +5,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/google/abseil-cpp-binary.git", "state" : { - "revision" : "7ce7be095bc3ed3c98b009532fe2d7698c132614", - "version" : "1.2024011601.0" + "revision" : "748c7837511d0e6a507737353af268484e1745e2", + "version" : "1.2024011601.1" } }, { @@ -14,8 +14,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/google/app-check.git", "state" : { - "revision" : "3e464dad87dad2d29bb29a97836789bf0f8f67d2", - "version" : "10.18.1" + "revision" : "7d2688de038d5484866d835acb47b379722d610e", + "version" : "10.19.0" } }, { @@ -23,8 +23,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/openid/AppAuth-iOS.git", "state" : { - "revision" : "7e2c09cbeb3bb799f26c268dbedb26325ea722a9", - "version" : "1.7.3" + "revision" : "c89ed571ae140f8eb1142735e6e23d7bb8c34cb2", + "version" : "1.7.5" } }, { @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/firebase/firebase-ios-sdk.git", "state" : { - "revision" : "fcf5ced6dae2d43fced2581e673cc3b59bdb8ffa", - "version" : "10.23.0" + "revision" : "42eae77a0af79e9c3f41df04a23c76f05cfdda77", + "version" : "10.24.0" } }, { @@ -41,8 +41,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/google/GoogleAppMeasurement.git", "state" : { - "revision" : "6ec4ca62b00a665fa09b594fab897753a8c635fa", - "version" : "10.23.0" + "revision" : "51ba746a9d51a4bd0774b68499b0c73ef6e8570d", + "version" : "10.24.0" } }, { @@ -77,8 +77,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/google/grpc-binary.git", "state" : { - "revision" : "67043f6389d0e28b38fa02d1c6952afeb04d807f", - "version" : "1.62.1" + "revision" : "e9fad491d0673bdda7063a0341fb6b47a30c5359", + "version" : "1.62.2" } }, { @@ -86,8 +86,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/google/gtm-session-fetcher.git", "state" : { - "revision" : "9534039303015a84837090d20fa21cae6e5eadb6", - "version" : "3.3.2" + "revision" : "0382ca27f22fb3494cf657d8dc356dc282cd1193", + "version" : "3.4.1" } }, { @@ -113,8 +113,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/firebase/leveldb.git", "state" : { - "revision" : "43aaef65e0c665daadf848761d560e446d350d3d", - "version" : "1.22.4" + "revision" : "a0bc79961d7be727d258d33d5a6b2f1023270ba1", + "version" : "1.22.5" } }, { @@ -140,8 +140,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/RevenueCat/purchases-ios", "state" : { - "revision" : "12240d045cfad9f281bc21e9f09d0c33ff09b74f", - "version" : "4.39.0" + "revision" : "9f46bb70940087ec9a95b1e9288710bb439549d8", + "version" : "4.41.1" } }, { @@ -149,8 +149,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-protobuf.git", "state" : { - "revision" : "65e8f29b2d63c4e38e736b25c27b83e012159be8", - "version" : "1.25.2" + "revision" : "9f0c76544701845ad98716f3f6a774a892152bcb", + "version" : "1.26.0" } } ], From 31768889f3ed05c285fe06f2da157fab5395485b Mon Sep 17 00:00:00 2001 From: Mirzamehdi Date: Sun, 28 Apr 2024 14:18:12 +0200 Subject: [PATCH 3/3] Updating api and version to 0.3.0 --- README.md | 2 +- gradle.properties | 2 +- kmprevenuecat-purchases-ui/kmprevenuecat_purchases_ui.podspec | 2 +- kmprevenuecat-purchases/api/kmprevenuecat-purchases.api | 3 +++ kmprevenuecat-purchases/kmprevenuecat_purchases.podspec | 2 +- 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c80c2e4..390dc2e 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Related Blog Post (if you want to integrate it yourself without this library): h - **Android:** `minSdkVersion 24` - **iOS:** `minDeploymentTarget 15.0` -- **RevenueCat Android version:** `7.5.2` +- **RevenueCat Android version:** `7.9.0` - **RevenueCat iOS version:** `4.41.1` ### Gradle Setup diff --git a/gradle.properties b/gradle.properties index 23b11e8..9bb4229 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,4 +18,4 @@ kotlin.mpp.enableCInteropCommonization=true #Development development=true -kmpRevenueCatVersion=0.2.0 \ No newline at end of file +kmpRevenueCatVersion=0.3.0 \ No newline at end of file diff --git a/kmprevenuecat-purchases-ui/kmprevenuecat_purchases_ui.podspec b/kmprevenuecat-purchases-ui/kmprevenuecat_purchases_ui.podspec index 3254885..ba85c79 100644 --- a/kmprevenuecat-purchases-ui/kmprevenuecat_purchases_ui.podspec +++ b/kmprevenuecat-purchases-ui/kmprevenuecat_purchases_ui.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'kmprevenuecat_purchases_ui' - spec.version = '0.2.0' + spec.version = '0.3.0' spec.homepage = '' spec.source = { :http=> ''} spec.authors = '' diff --git a/kmprevenuecat-purchases/api/kmprevenuecat-purchases.api b/kmprevenuecat-purchases/api/kmprevenuecat-purchases.api index e8c093b..86bc68f 100644 --- a/kmprevenuecat-purchases/api/kmprevenuecat-purchases.api +++ b/kmprevenuecat-purchases/api/kmprevenuecat-purchases.api @@ -16,6 +16,7 @@ public final class com/mmk/kmprevenuecat/purchases/CacheFetchPolicy$Companion { public final class com/mmk/kmprevenuecat/purchases/CoroutinesExtensionsKt { public static final fun awaitCustomerInfo (Lcom/mmk/kmprevenuecat/purchases/Purchases;Lcom/mmk/kmprevenuecat/purchases/CacheFetchPolicy;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun awaitCustomerInfo$default (Lcom/mmk/kmprevenuecat/purchases/Purchases;Lcom/mmk/kmprevenuecat/purchases/CacheFetchPolicy;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static final fun awaitSyncPurchases (Lcom/mmk/kmprevenuecat/purchases/Purchases;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } public abstract interface annotation class com/mmk/kmprevenuecat/purchases/KMPRevenueCatInternalApi : java/lang/annotation/Annotation { @@ -48,6 +49,7 @@ public abstract interface class com/mmk/kmprevenuecat/purchases/Purchases { public abstract fun setAttributes (Ljava/util/Map;)V public abstract fun setFirebaseAppInstanceID (Ljava/lang/String;)V public abstract fun setLogLevel (Lcom/mmk/kmprevenuecat/purchases/LogLevel;)V + public abstract fun syncPurchases (Lkotlin/jvm/functions/Function1;)V } public final class com/mmk/kmprevenuecat/purchases/Purchases$Companion : com/mmk/kmprevenuecat/purchases/Purchases { @@ -61,6 +63,7 @@ public final class com/mmk/kmprevenuecat/purchases/Purchases$Companion : com/mmk public fun setAttributes (Ljava/util/Map;)V public fun setFirebaseAppInstanceID (Ljava/lang/String;)V public fun setLogLevel (Lcom/mmk/kmprevenuecat/purchases/LogLevel;)V + public fun syncPurchases (Lkotlin/jvm/functions/Function1;)V } public final class com/mmk/kmprevenuecat/purchases/Purchases$DefaultImpls { diff --git a/kmprevenuecat-purchases/kmprevenuecat_purchases.podspec b/kmprevenuecat-purchases/kmprevenuecat_purchases.podspec index 3eb9f41..f91a8fc 100644 --- a/kmprevenuecat-purchases/kmprevenuecat_purchases.podspec +++ b/kmprevenuecat-purchases/kmprevenuecat_purchases.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'kmprevenuecat_purchases' - spec.version = '0.2.0' + spec.version = '0.3.0' spec.homepage = '' spec.source = { :http=> ''} spec.authors = ''