Skip to content

Commit 270eefc

Browse files
hyochannahlebn1k
andauthored
feat: add getStrongFront functionality on both ios and android (#3033)
## Description This PR adds the `getStrongFront` functionality to the React Native IAP library, implementing it on both iOS and Android platforms. ### Changes - **iOS Implementation**: Added `getStrongFront` method in `HybridRnIap.swift` using StoreKit 2 - **Android Implementation**: Added `getStrongFront` method in `HybridRnIap.kt` using Google Play Billing - **API Integration**: Exposed `getStrongFront` method in the main API (`src/index.ts`) - **Type Definitions**: Added TypeScript types for `getStrongFront` in `src/types.ts` - **Nitro Bridge**: Updated `src/specs/RnIap.nitro.ts` to include the new method - **Documentation**: Updated API documentation to include `getStrongFront` method - **Tests**: Added tests for the new `getStrongFront` functionality - **Example Updates**: Updated example apps to demonstrate `getStrongFront` usage ### Platform Details **iOS (StoreKit 2)**: - Returns storefront information including country code and identifier **Android (Google Play Billing)**: - Returns billing client region information ### Testing - All existing tests pass - New `getStrongFront` functionality tested on both platforms - Example a- **Andated and verified Co-authored-by: Myzynets <[email protected]> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * New Features * Unified, cross-platform storefront retrieval (replaces the previous iOS-only approach). * Example app now displays storefront and includes a “Refresh storefront” action with loading state. * Documentation * Updated storefront docs to note cross-platform support and empty-string behavior on unsupported platforms. * Consolidated notes in purchase request docs for clarity. * Marked the iOS-only storefront method as deprecated in favor of the unified API. * Tests * Added coverage for unified storefront retrieval and fallbacks. * Chores * Improved iOS example build path configuration. * Bumped an internal dependency version. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: Myzynets <[email protected]>
1 parent f1cc823 commit 270eefc

File tree

13 files changed

+210
-206
lines changed

13 files changed

+210
-206
lines changed

android/src/main/java/com/margelo/nitro/iap/HybridRnIap.kt

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,22 @@ class HybridRnIap : HybridRnIapSpec() {
490490
}
491491
}
492492
}
493-
493+
494+
override fun getStorefront(): Promise<String> {
495+
return Promise.async {
496+
try {
497+
initConnection().await()
498+
RnIapLog.payload("getStorefront", null)
499+
val value = openIap.getStorefront()
500+
RnIapLog.result("getStorefront", value)
501+
value
502+
} catch (e: Exception) {
503+
RnIapLog.failure("getStorefront", e)
504+
""
505+
}
506+
}
507+
}
508+
494509
override val memorySize: Long
495510
get() = 0L
496511

@@ -772,22 +787,6 @@ class HybridRnIap : HybridRnIapSpec() {
772787
}
773788
}
774789

775-
// Android-specific storefront getter
776-
override fun getStorefrontAndroid(): Promise<String> {
777-
return Promise.async {
778-
try {
779-
initConnection().await()
780-
RnIapLog.payload("getStorefrontAndroid", null)
781-
val value = openIap.getStorefront()
782-
RnIapLog.result("getStorefrontAndroid", value)
783-
value
784-
} catch (e: Exception) {
785-
RnIapLog.failure("getStorefrontAndroid", e)
786-
""
787-
}
788-
}
789-
}
790-
791790
// Android-specific deep link to subscription management
792791
override fun deepLinkToSubscriptionsAndroid(options: NitroDeepLinkOptionsAndroid): Promise<Unit> {
793792
return Promise.async {

docs/docs/api/methods/core-methods.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ const loadSubscriptions = async () => {
124124

125125
Initiates a purchase request for products or subscriptions.
126126

127-
> **📖 Reference:** [OpenIAP Request APIs](https://www.openiap.dev/docs/apis#request-apis)
128-
129-
> **⚠️ Platform Differences:**
127+
> **📖 Reference:** [OpenIAP Request APIs](https://www.openiap.dev/docs/apis#request-apis) **⚠️ Platform Differences:**
130128
>
131129
> - **iOS**: Can only purchase one product at a time (uses `sku: string`)
132130
> - **Android**: Can purchase multiple products at once (uses `skus: string[]`)
@@ -372,7 +370,7 @@ const openSubscriptionSettings = () => {
372370

373371
## getStorefront()
374372

375-
Return the storefront in ISO 3166-1 alpha-2 or ISO 3166-1 alpha-3 format
373+
Return the storefront in ISO 3166-1 alpha-2 or ISO 3166-1 alpha-3 format. Works on both iOS and Android—on other platforms it returns an empty string.
376374

377375
```tsx
378376
import {getStorefront} from 'react-native-iap';

example-expo/app/index-original.tsx

Lines changed: 0 additions & 145 deletions
This file was deleted.

example-expo/app/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {useEffect, useState} from 'react';
22
import {View, Text, StyleSheet, TouchableOpacity} from 'react-native';
33
import {Link} from 'expo-router';
4-
import {getStorefrontIOS} from 'react-native-iap';
4+
import {getStorefront} from 'react-native-iap';
55

66
/**
77
* Example App Landing Page
@@ -13,8 +13,8 @@ export default function Home() {
1313
const [storefront, setStorefront] = useState<string | null>(null);
1414

1515
useEffect(() => {
16-
// getStorefrontIOS already handles platform checks internally
17-
getStorefrontIOS()
16+
// getStorefront handles platform checks internally
17+
getStorefront()
1818
.then((storefront: any) => {
1919
setStorefront(storefront);
2020
})

example/ios/Podfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ prepare_react_native_project!
3030
target 'example' do
3131
config = use_native_modules!
3232

33+
# Force absolute app path to avoid overly nested relative paths in build scripts
34+
app_path = File.expand_path('..', __dir__)
35+
3336
use_react_native!(
3437
:path => config[:reactNativePath],
35-
# An absolute path to your application root.
36-
:app_path => "#{Pod::Config.instance.installation_root}/.."
38+
# Absolute path to the application root prevents runaway ../../ segments
39+
:app_path => app_path
3740
)
3841

3942
# Work around CDN/trunk propagation delay by pulling OpenIAP directly from Git.

example/ios/Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ PODS:
88
- hermes-engine (0.81.1):
99
- hermes-engine/Pre-built (= 0.81.1)
1010
- hermes-engine/Pre-built (0.81.1)
11-
- NitroIap (14.4.3):
11+
- NitroIap (14.4.5):
1212
- boost
1313
- DoubleConversion
1414
- fast_float
@@ -2747,10 +2747,10 @@ SPEC CHECKSUMS:
27472747
fmt: a40bb5bd0294ea969aaaba240a927bd33d878cdd
27482748
glog: 5683914934d5b6e4240e497e0f4a3b42d1854183
27492749
hermes-engine: 4f8246b1f6d79f625e0d99472d1f3a71da4d28ca
2750-
NitroIap: 0334bb6a2379907b20ba556d6ec49f0f94dc3e96
2750+
NitroIap: b3d39741d8528e63f258e4cccf14b3f04b5f1a02
27512751
NitroModules: d9c969e83c30ec1e7efc95e0ae58c21db1585c14
27522752
openiap: 92c66923a5aa128777da7dc6283a06b331eeab37
2753-
RCT-Folly: 846fda9475e61ec7bcbf8a3fe81edfcaeb090669
2753+
RCT-Folly: 59ec0ac1f2f39672a0c6e6cecdd39383b764646f
27542754
RCTDeprecation: c4b9e2fd0ab200e3af72b013ed6113187c607077
27552755
RCTRequired: e97dd5dafc1db8094e63bc5031e0371f092ae92a
27562756
RCTTypeSafety: 720403058b7c1380c6a3ae5706981d6362962c89
@@ -2819,6 +2819,6 @@ SPEC CHECKSUMS:
28192819
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
28202820
Yoga: fa23995c18b65978347b096d0836f4f5093df545
28212821

2822-
PODFILE CHECKSUM: 68a7c2afe0ade1366edc9327417ab94a1539b9b1
2822+
PODFILE CHECKSUM: f03bb7813aed3d3c0b30414d3d99a1a8d5d800c5
28232823

28242824
COCOAPODS: 1.15.2

0 commit comments

Comments
 (0)