包括 purchase 和 iap, gamecenter,等之后用到再补充
https://docs.godotengine.org/zh_CN/latest/tutorials/platform/services_for_ios.html
Store Kit
一些支付代码参考
https://gist.github.com/FEDE0D/8595c1cf5e0a3263fdbc
对应源码:platform/iphone/in_app_store.mm
https://github.com/godotengine/godot/blob/master/platform/iphone/in_app_store.mm
godot xcode部分源码
header定义
//获取产品信息
Error request_product_info(Variant p_params);
//恢复购买
Error restore_purchases();
//购买
Error purchase(Variant p_params);
//正在处理的事件数
int get_pending_event_count();
//抛出最旧(最前)一个事件,并返回此事件
Variant pop_pending_event();
//完成交易
void finish_transaction(String product_id);
//设置是否自动完成交易
void set_auto_finish_transaction(bool b);
//(内)发送事件
void _post_event(Variant p_event);
//(内)记录事件
void _record_purchase(String product_id);
//(内)单例
static InAppStore *get_singleton();
主文件下定义了链接:
void InAppStore::_bind_methods() {
ClassDB::bind_method(D_METHOD("request_product_info"), &InAppStore::request_product_info);
ClassDB::bind_method(D_METHOD("restore_purchases"), &InAppStore::restore_purchases);
ClassDB::bind_method(D_METHOD("purchase"), &InAppStore::purchase);
ClassDB::bind_method(D_METHOD("get_pending_event_count"), &InAppStore::get_pending_event_count);
ClassDB::bind_method(D_METHOD("pop_pending_event"), &InAppStore::pop_pending_event);
ClassDB::bind_method(D_METHOD("finish_transaction"), &InAppStore::finish_transaction);
ClassDB::bind_method(D_METHOD("set_auto_finish_transaction"), &InAppStore::set_auto_finish_transaction);
};
我想,这些经过绑定的函数,应该才是可以被调用的
先看purchase函数:
参数必须符合:包含product_id
关键字
发送支付申请
NSString *pid = [[[NSString alloc] initWithUTF8String:String(params["product_id"]).utf8().get_data()] autorelease];
SKPayment *payment = [SKPayment paymentWithProductIdentifier:pid];
SKPaymentQueue *defq = [SKPaymentQueue defaultQueue];
[defq addPayment:payment];
printf("purchase sent!\n");
iap 使用方法
获得单例
InAppStore = Engine.get_singleton("InAppStore")
激活购买 purchase必须包含关键字product_id
var result = InAppStore.purchase( { "product_id": "getpro" } )
if result == OK:
print("next action")
restore 恢复购买功能,无参数
var result = InAppStore.restore_purchases()
if result== OK:
当执行purchase和restore后result状态为ok(无异常)时,使用timer来反复侦听
func check_events_real():
if !InAppStore:
return
while InAppStore.get_pending_event_count() > 0:
var event = InAppStore.pop_pending_event()
if event.type == "purchase":
if event.result == "ok":
show_success(event.product_id)
else:
show_error()
var event = InAppStore.pop_pending_event() 中event对应参数
参数 | 数组 | 意义 |
---|---|---|
titles | 是 | 标题 |
descriptions | 是 | 描述 |
prices | 是 | 价格 |
ids | 是 | id组 |
localized_prices | 是 | 本地价格 |
currency_codes | 是 | 货币代码 |
type | 否 | 类型,purchase / restore |
result | 否 | 字符串:ok,error |
product_id | 否 | 当前id号 |
transaction_id | 否 | 当前交易id |
GameCenter
略
https://docs.godotengine.org/zh_CN/latest/tutorials/platform/services_for_ios.html
可以按照iap链接手法来处理
godot和ios之间通信不是对等的,ios无法请求godot方的函数,所以无论是发送还是获取信息,都是要godot来主动触发的。所以获取结果的时候就出现了需要循环去检索的方法(也是没办法)