quick3.3中CCStore的使用

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
 
---商店的回调
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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值