我正在使用Capacitor生成IOS和Android应用程序(不使用Iconic(-这很好,但我们正在尝试实现IAP(现阶段仅适用于IOS(,但无法解决。
我遵循了各种指南(https://ionicframework.com/docs/native/in-app-purchase-2和https://purchase.cordova.fovea.cc/和https://capacitorjs.com/docs/guides/in-app-purchases)但根本无法使其与React(非React Native(一起工作
有人能为我指明正确的方向吗,或者提供示例代码?
您没有描述出了什么问题,但这里有一个在iOS上适用的基本配置。
我只包括关于商店的部分:
索引.tsx
import { IAPProduct, InAppPurchase2 } from '@ionic-native/in-app-purchase-2';
const startStoreEventListeners = () => {
if (isPlatformMobile()) {
document.addEventListener(
'deviceready',
() => {
const store = InAppPurchase2;
// Needed to use IAP + cordova plugins.
// Set debug messages.
// Default.
store.verbosity = store.QUIET;
// store.verbosity = store.DEBUG;
store.register([
{
id: subMonthly,
type: store.PAID_SUBSCRIPTION,
},
{
id: subAnnual,
type: store.PAID_SUBSCRIPTION,
},
]);
// Upon approval, verify the receipt.
store.when(subMonthly).approved((product: IAPProduct) => {
product.verify();
});
store.when(subAnnual).approved((product: IAPProduct) => {
product.verify();
});
// Upon receipt validation, mark the subscription as owned.
store.when(subMonthly).verified((product: IAPProduct) => {
product.finish();
});
store.when(subAnnual).verified((product: IAPProduct) => {
product.finish();
});
// Track all store errors
store.error((err: Error) => {
debugLog('Store Error', JSON.stringify(err));
});
// https://billing-dashboard.fovea.cc/setup/cordova
store.validator =
'https://validator.fovea.cc/v1/validate?appName=secret';
store.refresh();
startIonic();
},
false,
);
} else {
startIonic();
}
};
startStoreEventListeners();
serviceWorker.unregister();
请注意,@ionic本机包已弃用,需要进行转换。