React native module for checking subscription status
$ npm install react-native-native-subscription --save
$ react-native link react-native-native-subscription
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜react-native-native-subscription
and addRNNativeSubscription.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNNativeSubscription.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Run your project (
Cmd+R
)<
import RNNativeSubscription from 'react-native-native-subscription';
RNNativeSubscription.hasPurchasedSubscriptionForProductID(
productID,
).then((hasPurchaseResponse: any) => {
console.log('hasPurchaseResponse: ', hasPurchaseResponse);
if (hasPurchaseResponse['status'] == 'success') {
let hasPurchase =
hasPurchaseResponse['has_purchase'] == 'YES' ? true : false;
if (hasPurchase) {
RNNativeSubscription.isSubscribedForProductID(productID).then(
(subscriptionResponse: any) => {
console.log('subscriptionResponse: ', subscriptionResponse);
if (subscriptionResponse['status'] == 'success') {
let isSubscribed =
subscriptionResponse['is_subscribed'] == 'YES'
? true
: false;
console.log('isSubscribed: ', isSubscribed);
if (isSubscribed) {
// execute code for subscribed user
} else {
// execute code to show user subscription plan
// The user was subscribed earlier, but the plan got expired/not renewed
}
} else {
console.log("Failed to check subscriptions status: ", subscriptionResponse['message'])
}
},
);
}
} else {
// The user has never subscribed. Show the subscription plans
}
})