我想在 iOS 上的 RoboVM 应用中使用应用内购买。据我所知,我需要访问Apples StoreKit 框架。我找到了以下解决方案:
我想知道对我来说最好的方式是什么。我首先尝试了 gdx-pay ,但我不需要跨平台解决方案。 robovm-ios-bindings 似乎只关注我需要的功能。但由于它被标记为已弃用,我有疑问。 robopods 会很棒,因为它被RoboVM网站引用,但我找不到StoreKid绑定。
我正在尝试查找有关如何使用其中一种技术的文档/教程。 E.g
答案 0 :(得分:1)
Gdx-Pay 是最简单的方法。 https://xyz.example.com包含实施它所需的所有信息。
测试无法用真钱完成。您可以设置测试环境以测试购买,如下所述:This
必须遵循的Apple规则是“恢复”#34;购买按钮。例如,您的用户必须明确要求恢复购买,例如按钮。
以下是我如何设置Gdx-Pay的示例:
if(PurchaseSystem.hasManager()){
config = new PurchaseManagerConfig();
config.addOffer(new Offer().setType(OfferType.ENTITLEMENT).setIdentifier(item1String));
//Stores
config.addStoreParam(PurchaseManagerConfig.STORE_NAME_ANDROID_GOOGLE, base64EncodedKey);
config.addStoreParam(PurchaseManagerConfig.STORE_NAME_IOS_APPLE, base64EncodedKey); // <-- CHANGE KEY
PurchaseSystem.install(new PurchaseObserver() {
@Override
public void handleInstall() {
message(" - purchase manager installed: " + PurchaseSystem.storeName() + ".\n");
// restore purchases
message(" - do a restore to check inventory\n");
//Execute this on a button instead!
PurchaseSystem.purchaseRestore();
}
@Override
public void handleInstallError(Throwable e) {
message(" - error installing purchase manager: " + e + "\n");
// throw error
throw new GdxRuntimeException(e);
}
@Override
public void handleRestore(Transaction[] transactions) {
// keep note of our purchases
message(" - totally " + transactions.length + " purchased products\n");
for (int i = 0; i < transactions.length; i++) {
if(transactions[i].getIdentifier().equals(stone1)) {
preferences.putBoolean("item1_purchased", true);
}
}
}
@Override
public void handleRestoreError(Throwable e) {
message(" - error during purchase manager restore: " + e + "\n");
// throw error
throw new GdxRuntimeException(e);
}
@Override
public void handlePurchase(Transaction transaction) {
message(" - purchased: " + transaction.getIdentifier() + "\n");
// dispose the purchase system
Gdx.app.postRunnable(new Runnable() {
@Override
public void run () {
message(" - disposing the purchase manager.\n");
PurchaseSystem.dispose();
message("Testing InApp System: COMPLETED\n");
}
});
}
@Override
public void handlePurchaseError(Throwable e) {
message(" - error purchasing: " + e + "\n");
// throw error
throw new GdxRuntimeException(e);
}
@Override
public void handlePurchaseCanceled() {
message(" - purchase cancelled.\n");
// dispose the purchase system
Gdx.app.postRunnable(new Runnable() {
@Override
public void run () {
message(" - user canceled! - disposing the purchase manager.\n");
PurchaseSystem.dispose();
message("Testing InApp System: COMPLETED\n");
}
});
}
},config);
} else {
//Toast an error
}
然后你可以打电话
PurchaseSystem.purchase("itemID");
进行购买。