尼玛,刚刚编辑了一个小时的帖子点了发布然后就没了,没了,没了,我擦
之前的帖子真的没了,好吧,我只能再写一遍,我了个擦啊!
本文简要介绍quick中针对ios的iap功能封装的CCStore
1.CCStore源码和导出的lua的api在哪里
a. iaptest2/frameworks/runtime-src/Classes/quick-src/extra/store/CCStore.h
b.iaptest2/src/framework/cc/sdk/Store.lua
是的,iaptest2就是项目目录
2.首先,在当前版本中要想正常使用CCStore需要修改两个地方
a.图中标明的两处替换为cc.Store
b.图中三处变量添加cc前缀
修改完毕,现在就可以正常使用了
3.关于ios工程如何开启iap支持,可以参考下面的帖子的前面的部分,这里不做啰嗦,因为quick的ios工程终极也是ios工程,没区别
参考帖子:http://www.tairan.com/archives/5515
4.好了,现在我假定看官们已经开启了ios工程的iap支持,也在itunesconnect添加了测试商品以及测试账号
本文的代码如下:
function MainScene:ctor()
--初始化商店
Store.init(handler(self, self.storeCallback)) --function(event) self:storeCallback(event) end)
--载入商品
Store.loadProducts({"com.originaljoy.iaptest.222coin",
"com.originaljoy.iaptest.11coin",
"com.originaljoy.iaptest.111coin",
"com.originaljoy.iaptest2.1111coin"
}, handler(self, self.loadCallback))
--添加一个购买按钮
self.btn = cc.ui.UIPushButton.new("ui_btn_start.png")
:onButtonClicked(function(event)
print("购买商品")
Store.purchase("com.originaljoy.iaptest2.1111coin")
end)
:pos(display.cx, display.cy)
:addTo(self)
end
---商店的回调
function MainScene:storeCallback(transaction)
--处理购买中的事件回调,如购买成功
if transaction.transaction.state == "purchased" then
print("buy success")
Store.finishTransaction(transaction.transaction)
end
end
---载入商品的毁掉
function MainScene:loadCallback(products)
--返回商品列表
dump(products)
end
```
5.store的api使用
a.Store.init(listener)
初始化商店,并设置回调函数。回调函数用来处理各种store事件,接受一个参数event
event包含一个字段,transaction! transaction就是事件的完整内容,下图就是一次购买成功后回调的transaction
b.Store.loadProducts(productsId, listener)
载入商品列表,并设置回调
回调函数接受一个参数,就是商品列表,包括可用和不可用的商品,如图
c.Store.purchase(productId)
购买一个商品,传入商品id!购买事件将会在store的回调中接收
d.Store.finishTransaction(transaction)
移除一个事件。如果你购买一个商品成功后,不移除对应的事件,再次购买会有如下提示:
this in-app purchase has already been bought it will be restored for free
以上就是重要的几个函数的使用了!
因为赶刚编辑了很久的帖子就那么没了,所以没有心再写那么详细了,大概就这样,对于本文的疑问,可以在quick群里@三刀就好了
使用完的感受就是:用quick,就这么简单!




顶完再看