Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #13 from mirzemehdi/rel_0.3.0
Browse files Browse the repository at this point in the history
Relase candidate for version 0.3.0
  • Loading branch information
mirzemehdi authored Apr 28, 2024
2 parents 5bf8f61 + 3176888 commit d8b057e
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 50 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ 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 iOS version:** `4.39.0`
- **RevenueCat Android version:** `7.9.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.
Expand Down Expand Up @@ -57,6 +57,7 @@ fun setAttributes(attributes: Map<String,String?>)
fun setFirebaseAppInstanceID(firebaseAppInstanceID: String)
fun collectDeviceIdentifiers()
fun enableAdServicesAttributionTokenCollection()
fun syncPurchases(onResult: (Result<CustomerInfo>) -> Unit)

```
### Purchases-UI
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ kotlin.mpp.enableCInteropCommonization=true
#Development
development=true

kmpRevenueCatVersion=0.2.0
kmpRevenueCatVersion=0.3.0
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"



Expand Down
6 changes: 3 additions & 3 deletions kmprevenuecat-purchases-ui/kmprevenuecat_purchases_ui.podspec
Original file line number Diff line number Diff line change
@@ -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 = ''
Expand All @@ -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 "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 3 additions & 0 deletions kmprevenuecat-purchases/api/kmprevenuecat-purchases.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions kmprevenuecat-purchases/kmprevenuecat_purchases.podspec
Original file line number Diff line number Diff line change
@@ -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 = ''
Expand All @@ -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 "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -83,4 +86,16 @@ internal class PurchasesImpl(private val context: Context) : Purchases {
}

override fun enableAdServicesAttributionTokenCollection() = Unit
@OptIn(KMPRevenueCatInternalApi::class)
override fun syncPurchases(onResult: (Result<CustomerInfo>) -> 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()))
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ public interface Purchases {
public fun setFirebaseAppInstanceID(firebaseAppInstanceID: String)
public fun collectDeviceIdentifiers()
public fun enableAdServicesAttributionTokenCollection()

public fun syncPurchases(onResult: (Result<CustomerInfo>) -> Unit)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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))
},
)
}
}
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -37,15 +39,9 @@ internal class PurchasesImpl : Purchases {
})
}

@OptIn(KMPRevenueCatInternalApi::class)

override fun logOut(onResult: (Result<CustomerInfo>) -> 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(
Expand All @@ -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<String,String?>){
override fun setAttributes(attributes: Map<String, String?>) {
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)
}

Expand All @@ -82,4 +73,17 @@ internal class PurchasesImpl : Purchases {
RCPurchases.sharedPurchases().attribution().enableAdServicesAttributionTokenCollection()
}

override fun syncPurchases(onResult: (Result<CustomerInfo>) -> Unit) {
RCPurchases.sharedPurchases()
.syncPurchasesWithCompletion(completion = onCompletionHandler(onResult))
}

@OptIn(KMPRevenueCatInternalApi::class)
private fun onCompletionHandler(onResult: (Result<CustomerInfo>) -> Unit): ((RCCustomerInfo?, NSError?) -> Unit) {
return { rcCustomerInfo, nsError ->
if (rcCustomerInfo != null) onResult(Result.success(rcCustomerInfo.asCustomerInfo()))
else onResult(Result.failure(Exception(nsError?.localizedFailureReason)))
}
}

}
2 changes: 1 addition & 1 deletion sampleApp/iosApp/iosApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,44 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/abseil-cpp-binary.git",
"state" : {
"revision" : "7ce7be095bc3ed3c98b009532fe2d7698c132614",
"version" : "1.2024011601.0"
"revision" : "748c7837511d0e6a507737353af268484e1745e2",
"version" : "1.2024011601.1"
}
},
{
"identity" : "app-check",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/app-check.git",
"state" : {
"revision" : "3e464dad87dad2d29bb29a97836789bf0f8f67d2",
"version" : "10.18.1"
"revision" : "7d2688de038d5484866d835acb47b379722d610e",
"version" : "10.19.0"
}
},
{
"identity" : "appauth-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/openid/AppAuth-iOS.git",
"state" : {
"revision" : "7e2c09cbeb3bb799f26c268dbedb26325ea722a9",
"version" : "1.7.3"
"revision" : "c89ed571ae140f8eb1142735e6e23d7bb8c34cb2",
"version" : "1.7.5"
}
},
{
"identity" : "firebase-ios-sdk",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/firebase-ios-sdk.git",
"state" : {
"revision" : "fcf5ced6dae2d43fced2581e673cc3b59bdb8ffa",
"version" : "10.23.0"
"revision" : "42eae77a0af79e9c3f41df04a23c76f05cfdda77",
"version" : "10.24.0"
}
},
{
"identity" : "googleappmeasurement",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleAppMeasurement.git",
"state" : {
"revision" : "6ec4ca62b00a665fa09b594fab897753a8c635fa",
"version" : "10.23.0"
"revision" : "51ba746a9d51a4bd0774b68499b0c73ef6e8570d",
"version" : "10.24.0"
}
},
{
Expand Down Expand Up @@ -77,17 +77,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/grpc-binary.git",
"state" : {
"revision" : "67043f6389d0e28b38fa02d1c6952afeb04d807f",
"version" : "1.62.1"
"revision" : "e9fad491d0673bdda7063a0341fb6b47a30c5359",
"version" : "1.62.2"
}
},
{
"identity" : "gtm-session-fetcher",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/gtm-session-fetcher.git",
"state" : {
"revision" : "9534039303015a84837090d20fa21cae6e5eadb6",
"version" : "3.3.2"
"revision" : "0382ca27f22fb3494cf657d8dc356dc282cd1193",
"version" : "3.4.1"
}
},
{
Expand All @@ -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"
}
},
{
Expand All @@ -140,17 +140,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/RevenueCat/purchases-ios",
"state" : {
"revision" : "12240d045cfad9f281bc21e9f09d0c33ff09b74f",
"version" : "4.39.0"
"revision" : "9f46bb70940087ec9a95b1e9288710bb439549d8",
"version" : "4.41.1"
}
},
{
"identity" : "swift-protobuf",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-protobuf.git",
"state" : {
"revision" : "65e8f29b2d63c4e38e736b25c27b83e012159be8",
"version" : "1.25.2"
"revision" : "9f0c76544701845ad98716f3f6a774a892152bcb",
"version" : "1.26.0"
}
}
],
Expand Down

0 comments on commit d8b057e

Please sign in to comment.