第一节 iOS恢复购买
一、代码事例:
iOS的购买分为可恢复与不可恢复购买,可恢复购买比如武器、解锁的关卡、新角色等;不可恢复购买比如金币、钻石等消耗品。
用户在购买过道具后,删除游戏后又重新下载了游戏,或者同一个apple id帐号登录了其他iOS设备,此时游戏需能恢复用户已购买的非消耗性道具。
针对可恢复的购买,代码需做以下处理:
需在UI主界面放置一个按钮,上面有"Restore Purchases"的字样,默认不可见,其余代码如下:
if (this.hs_gameEngine.getPlatform() == "IOS") {
if (this.hs_gamedataAddin.getSystemVariate(xxx).getValue() == 0) { //超全局系统变量
var btn_Restore = sender.getControl("button_Restore");
btn_Restore.setVisible(true);
btn_Restore.addMouseUpDown("iOS_Btn_Restore_Mouse");
}
}
function iOS_Btn_Restore_Mouse(sender, e) {
var mouseType = e.getMouseType();
if (mouseType == 0) { //mouseDown
menuSelectPlayer.start();
} else if (mouseType == 1) {
this.hs_gameEngine.invokeThirdpartyInterface("iOS_restore", null);
this.hs_uiAddin.createDialog("xxxrestoreXXX.u").showDialog();
}
}
function iOS_RestoreCallback(result) {
if (result) {
xxxUIForm.getControl("button_Restore").setVisible(false);
this.hs_gamedataAddin.getSystemVariate(xxx).setValue(1);
this.hs_gameEngine.saveSuperSystemVariates();
this.showTips("restore success!");
} else {
this.showTips("restore failed!");
}
}
function hs_ChargeCallback(result, payType, arg) {
if (result != 0) {
if (arg == "iOS_restore") {
this.iOS_showTips("Restore Failed!");
return;
}
}
switch (payType) {
case 1:
//...
if (arg == "iOS_restore") {
//若正常购买涉及到窗体关闭之类,此处应该不处理,直接把道具给到玩家。
}
//...
break;
}
}
回到顶部
返回目录