Swiftpack.co - GroupeMINASTE/UnlockPremium as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by GroupeMINASTE.
GroupeMINASTE/UnlockPremium 1.0.1
A package to include a standard "Unlock premium" view in iOS and Android apps
⭐️ 1
🕓 3 weeks ago
iOS
.package(url: "https://github.com/GroupeMINASTE/UnlockPremium.git", from: "1.0.1")

UnlockPremium

License Issues Pull Requests Code Size Translation status

Installation

iOS

Add https://github.com/GroupeMINASTE/UnlockPremium.git to your Swift Package configuration (or using the Xcode menu: File > Swift Packages > Add Package Dependency)

Don't forget to add the In-App Purchase capability to your app (in Signing & Capabilities). This should automatically add the StoreKit framework to your app as well.

Android

Add the following to your build.gradle file:

repositories {
    mavenCentral()
}

dependencies {
    implementation 'me.nathanfallet.unlockpremium:unlockpremium:1.0.0'
}

Usage

iOS

Setup a configuration for the unlock view:

import UnlockPremium

extension UnlockPremiumConfig {

    static func config() -> UnlockPremiumConfig {
        return UnlockPremiumConfig(
            arguments: [
                PremiumArgument(
                    title: "A feature name",
                    description: "A feature description",
                    icon: "app.fill"
                ),
                // ...
            ],
            productIdentifier: "myAppSKU.premiumPurchase", // In-App Purchase `Product ID`
            completionHandler: {
                // Set your user as premium, for example:
                UserService.shared.setUserPremium(to: true)
            }
        )
    }

}

The completionHandler is the method called when the purchase completes successfully.

Then, show the view where you want:

.sheet(isPresented: $viewModel.showPremium) {
    UnlockPremiumView(configuration: .config(), isPresented: $viewModel.showPremium)
}

Android

Setup a configuration for the unlock view:

val config = UnlockPremiumConfig(
    listOf(
        PremiumArgument(
            "A feature name",
            "A feature description",
            R.drawable.ic_baseline_apps_24
        ),
        // ...
    ),
    "myAppSKU.premiumPurchase"
)

Create a request, and handle the response

private val unlockPremiumRequest = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { it ->
    it.data?.getBooleanExtra(UnlockPremiumActivity.EXTRAS.SUCCESS, false)?.let { success ->
        if (success) {
            // Set your user as premium, for example:
            UserService.getInstance(getApplication()).setUserPremium(true)
        }
    }
}

Then, show the view where you want:

val intent = Intent(this, UnlockPremiumActivity::class.java)
intent.putExtra(UnlockPremiumActivity.EXTRAS.CONFIGURATION, config)
unlockPremiumRequest.launch(intent)

GitHub

link
Stars: 1
Last commit: 3 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

UnlockPremium v1.0.1
3 weeks ago

Adding Spanish translations for UI

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics