quick3.3中CCStore的使用

来源:互联网 发布:辐射4帅男捏脸数据教程 编辑:程序博客网 时间:2024/05/22 14:14
1.CCStore源码和导出的lua的api在哪里
你的项目根目录/frameworks/runtime-src/Classes/quick-src/extra/store/CCStore.h
你的项目根目录/src/framework/cc/sdk/Store.lua

2.首先,在当前版本中要想正常使用CCStore需要修改两个地方
a.图中标明的两处替换为cc.Store



b.图中三处变量添加cc前缀

 

修改完毕,现在就可以正常使用了


3.关于ios工程如何开启iap支持,可以参考下面的帖子的前面的部分,这里不做啰嗦,因为quick的ios工程终极也是ios工程,没区别
参考帖子:http://www.tairan.com/archives/5515


4.好了,现在我假定看官们已经开启了ios工程的iap支持,也在itunesconnect添加了测试商品以及测试账号
本文的代码如下:


?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
 
---商店的回调
functionMainScene:storeCallback(transaction)
    --处理购买中的事件回调,如购买成功
    iftransaction.transaction.state == "purchased"then
    print("buy success")
    Store.finishTransaction(transaction.transaction)
    end
end
 
---载入商品的毁掉
functionMainScene: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
0 0