Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nathanfallet/unlockpremium
A package to include a standard "Unlock premium" view in iOS and Android apps
https://github.com/nathanfallet/unlockpremium
android iap kotlin kotlin-library spm swift
Last synced: about 1 month ago
JSON representation
A package to include a standard "Unlock premium" view in iOS and Android apps
- Host: GitHub
- URL: https://github.com/nathanfallet/unlockpremium
- Owner: nathanfallet
- License: gpl-3.0
- Created: 2022-04-15T07:57:20.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-05-08T17:32:06.000Z (over 1 year ago)
- Last Synced: 2024-05-01T17:45:48.677Z (7 months ago)
- Topics: android, iap, kotlin, kotlin-library, spm, swift
- Language: Kotlin
- Homepage:
- Size: 145 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# UnlockPremium
[![License](https://img.shields.io/github/license/NathanFallet/UnlockPremium)](LICENSE)
[![Issues](https://img.shields.io/github/issues/NathanFallet/UnlockPremium)]()
[![Pull Requests](https://img.shields.io/github/issues-pr/NathanFallet/UnlockPremium)]()
[![Code Size](https://img.shields.io/github/languages/code-size/NathanFallet/UnlockPremium)]()
[![Translation status](http://weblate.groupe-minaste.org/widgets/unlockpremium/-/svg-badge.svg)](http://weblate.groupe-minaste.org/engage/unlockpremium/?utm_source=widget)## Installation
### iOS
Add `https://github.com/NathanFallet/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:
```groovy
repositories {
mavenCentral()
}dependencies {
implementation 'me.nathanfallet.unlockpremium:unlockpremium:1.0.0'
}
```## Usage
### iOS
Setup a configuration for the unlock view:
```swift
import UnlockPremiumextension 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:
```swift
.sheet(isPresented: $viewModel.showPremium) {
UnlockPremiumView(configuration: .config(), isPresented: $viewModel.showPremium)
}
```### Android
Setup a configuration for the unlock view:
```kotlin
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
```kotlin
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:
```kotlin
val intent = Intent(this, UnlockPremiumActivity::class.java)
intent.putExtra(UnlockPremiumActivity.EXTRAS.CONFIGURATION, config)
unlockPremiumRequest.launch(intent)
```