ios - Ionic 3,IOS,应用内购买
问题描述
我已经在我的应用程序中将 IAP 实现为订阅,即如果成功,我会尝试恢复购买我说用户已订阅,否则我说他没有。如果他不这样做,我会让他订阅我的应用程序。
在多次被 Apple 拒绝后,昨天我们接到一个电话,他们声称我的恢复机制无法正常工作,我需要重新编写这部分代码。
(附服务)
首先,我不明白他们怎么知道我是如何使用该应用程序的,因为 js 被丑化了。
我正在使用 Ionic 3 和应用内购买 1 离子插件。
附代码
import { Injectable } from '@angular/core';
import * as _ from "lodash";
import {DbProvider} from "../db/db";
import {AlertController, Platform, ToastController} from "ionic-angular";
import {AuthProvider} from "../auth/auth";
import {TranslationProvider} from "../translation/translation";
import {InAppPurchase} from "@ionic-native/in-app-purchase";
import {TRIAL_PERIOD} from "../../app/app.constants";
/*
Generated class for the BillingProvider provider.
See https://angular.io/guide/dependency-injection for more info on providers
and Angular DI.
*/
@Injectable()
export class BillingProvider {
product_id;
inTrial;
cashPay;
subscriber;
get isPaying() {
if(this.inTrial){
return true;
} else {
return this.cashPay || this.subscriber;
}
}
constructor(private db: DbProvider, private alertCtrl: AlertController, private auth: AuthProvider, private translate: TranslationProvider, private toastCtrl: ToastController,
private iapp: InAppPurchase, private platform: Platform) {
this.init()
}
private async init() {
await this.platform.ready();
const product_ids = await this.db.getProductId();
if (this.platform.is('ios')) {
this.product_id = product_ids['ios'];
} else {
this.product_id = product_ids['android'];
}
await this.loadSubscribe();
const {joined} = this.auth.currentUser;
const joinDate = new Date(parseInt(joined));
const diff = new Date().getTime() - joinDate.getTime();
this.inTrial = diff < TRIAL_PERIOD;
const inTrial = this.inTrial;
this.auth.updateUser({inTrial});
const {paying} = this.auth.currentUserText;
this.cashPay = !!paying;
}
private async loadSubscribe() {
try {
const rawProducts = await this.iapp.restorePurchases();
const products = JSON.stringify(rawProducts);
this.auth.updateUser({products});
const subscriber = !!_.find(rawProducts, {productId : this.product_id});
this.auth.updateUser({subscriber});
this.subscriber = subscriber;
} catch (e) {
console.log(e);
}
}
private cashBuy(res, rej) {
const alert = this.alertCtrl.create({
title: this.translate.translate('Pay by cash request'),
message: this.translate.translate('Please fill the details below'),
inputs: [
{
name: 'name',
placeholder: this.translate.translate('Full name')
},
{
name: 'mail',
placeholder: this.translate.translate('Email')
},
{
name: 'phone',
placeholder: this.translate.translate('Phone number')
}
],
buttons: [
{
text: this.translate.translate('Cancel'),
handler: data => rej()
},
{
text: this.translate.translate('Submit'),
handler: data => {
const user = this.auth.currentUserText;
const row = _.pickBy({...data, ...user}, e => e);
this.db.addCashRequest(row);
const t = this.toastCtrl.create({
message: this.translate.translate('We got your request, we will contact you soon.'),
duration: 3000,
position: 'bottom'
});
t.present();
rej()
}
}
]
});
alert.present()
// asdasd
}
public buy() {
return new Promise((res, rej) => {
const alert = this.alertCtrl.create({
title: this.translate.translate('Confirm purchase'),
message: this.translate.translate('What Source you want to buy from'),
buttons: [
{
text: this.translate.translate('From Store'),
handler: () => {
this.iapp.subscribe(this.product_id).then(res).catch(rej);
}
},
{
text: this.translate.translate('By Cash'),
handler: () => {
this.cashBuy(res, rej);
}
}
]
});
alert.present();
})
}
}
解决方案
推荐阅读
- r - 在 R 中有一列具有 205550 个值,并且想要 10 列,其中值 1 进入第 1 列,值 2 进入第 2 列等
- python - 如何在 django 中创建一个传入多个对象的字典的自定义模板标签
- rmi - RMI 中的存根和 RPC 中的存根有什么区别?
- sql - 将带有信息的 Varchar 拆分为表格
- unity3d - 如何在不使用 public 的情况下编写脚本?
- python - 使用 Pandas 进行 JSON 到 Excel 的转换是将整个 JSON 文件放在 1 个 Excel 单元格中
- visual-studio - Unity - TextMeshPro 文本对象不更新
- rust - 使用可变引用覆盖变量时借用检查器错误
- javascript - Edge、Mozilla、Chrome 中的闪烁问题
- scala - 如何在scala中仅对元组的一个元素应用聚合