将 应用内 购买添加到您的 React Native 应用
使用 Adapty 的 React Native SDK 在 iOS 和 Android 上集成应用内购买。处理收据,跟踪订阅状态,消除构建后端的需要。所有功能都在一个集成中。
// Your app's code
import { adapty } from 'react-native-adapty';
await adapty.activate('YOUR_APP_KEY');
// Make a purchase, Adapty handles the rest
try {
const purchaseResult = await adapty.makePurchase(product);
if (purchaseResult.type === 'success') {
const profile = purchaseResult.profile;
// successful purchase
}
} catch (error) {
// handle the error
}
您无需为 React Native 应用内 购买构建后端
Adapty的SDK处理通常在服务器上进行的所有操作:收据验证、订阅状态、续订、试用和退款。您只需连接一次,即可获得适用于iOS和Android的工作React Native内购设置。
安排演示为什么选择 Adapty SDK?
跨平台跟踪订阅状态
您将始终知道用户在 iOS 和 Android 上是否具有有效订阅。
在后端验证收据
无需自行构建验证,Adapty 会处理。
处理各种订阅状态
免费试用,升级,促销优惠,家庭共享,续订等等。
在企业级核心上扩展
我们经常发布更新,保持 SDK 稳定,并运行在 >99.99% 的 SLA 上。
配置平台
安装 Adapty SDK
await adapty.activate( 'PUBLIC_SDK_KEY', { customerUserId: 'YOUR_USER_ID', });
处理购买事件
使用 5 个 SDK 方法处理 React Native IAP
// Your app's code
try {
const purchaseResult = await adapty.makePurchase(product);
switch (purchaseResult.type) {
case 'success':
const isSubscribed = purchaseResult.profile?.accessLevels['YOUR_ACCESS_LEVEL']?.isActive;
if (isSubscribed) {
// Grant access to the paid features
}
break;
case 'user_cancelled':
// Handle the case where the user canceled the purchase
break;
case 'pending':
// Handle deferred purchases (e.g., the user will pay offline with cash)
break;
}
} catch (error) {
// Handle the error
}
// Your app's code
try {
const profile = await adapty.restorePurchases();
const isSubscribed = profile.accessLevels['YOUR_ACCESS_LEVEL']?.isActive;
if (isSubscribed) {
// restore access
}
} catch (error) {
// handle the error
}
// Your app's code
try {
await adapty.identify("YOUR_USER_ID");
// successfully identified
} catch (error) {
// handle the error
}
// Your app's code
try {
await adapty.updateProfile(params);
} catch (error) {
// handle `AdaptyError`
}
// Your app's code
import { adapty, AttributionSource } from 'react-native-adapty';
import appsFlyer from 'react-native-appsflyer';
appsFlyer.onInstallConversionData(installData => {
try {
const uid = appsFlyer.getAppsFlyerUID();
adapty.setIntegrationIdentifier("appsflyer_id", uid);
adapty.updateAttribution(installData, "appsflyer");
} catch (error) {
// handle the error
}
});
// ...
appsFlyer.initSdk(/*...*/);
Adapty 为每个阶段的应用提供支持,从独立开发者到顶级出版商
一切您需要的来成长您的应用— 已经在 React Native SDK 中




常见问题
我如何在 React Native 中实施应用内购买?
要在 React Native 中设置应用内购买,您可以使用 Adapty 的 SDK,不必使用 react-native-iap。它适用于 iOS 和 Android,并可以直接处理订阅,包括分析、收据验证等。
需要帮助?我们有一个 React Native IAP 教程,里面有代码示例。
Adapty 和 react-native-iap 有什么不同?
React-native-iap 使您可以访问商店 API,但其他所有内容如订阅逻辑、A/B 测试、分析都必须自己构建。Adapty 替代了大部分功能。一个 SDK 处理订阅、付费墙和收入跟踪,无需后端。
我需要构建自己的后端以使用 Adapty 吗?
不,您不需要。Adapty 处理订阅管理和服务器端验证。您不必像在 react-native-iap 中那样手动处理
getSubscriptions
、requestSubscription
或收据检查。Adapty 支持 iOS 和 Android 吗?
当然。我们的 SDK 支持在 iOS 和 Android 上的 React Native 应用内购买,包括使用 Expo 或 react-native-iap 的应用。
在哪里可以找到代码示例和文档?
您可以通过设置指南、React Native 订阅示例和有关处理购买、升级和续订的详细说明,探索React Native IAP 文档。