2015-08-30 42 views
1

所以我试图在我的精灵套件游戏的应用程序购买实现,我在斯威夫特工作。我知道我需要在SKProductsRequestDelegateSKPaymentTransactionObserver协议添加到我的GameScene类,为了做到这一点,但是当我加入他们,我得到的错误:Swift:无法将SKProductsRequestDelegate协议添加到GameScene类中?

Type 'GameScene' does not conform to protocol 'SKProductsRequestDelegate' 

SKPaymentTransactionObserver类似的错误。

我进口StoreKit这里是我的代码:

import SpriteKit 
import AVFoundation 
import StoreKit 

class GameScene: SKScene, SKPhysicsContactDelegate, SKProductsRequestDelegate, SKPaymentTransactionObserver { 

我在做什么错?

+1

声称一致性是不够的,你实际上必须实现协议所需的方法。我认为SKProductsRequestDelegate有一个子协议。但总而言之,你确定GameScene是应该处理商店交易的类吗?我更喜欢单独的类处理商店交易,没有别的。 – gnasher729

+0

哪里可以找到协议的方法? – skyguy

+0

查看标记为_Required_ [here]的方法(https://developer.apple.com/library/ios/documentation/StoreKit/Reference/SKProductsRequestDelegate/#//apple_ref/occ/intfm/SKProductsRequestDelegate/productsRequest:didReceiveResponse :) and [这里](https://developer.apple.com/library/ios/documentation/StoreKit/Reference/SKPaymentTransactionObserver_Protocol/) – 0x141E

回答

0

我对Swift(尚未)不熟悉,但似乎Swift调用协议是我们其他人称为Interface
如果我是对的,那么你需要自己实现协议“签名”的所有方法(即承诺你的类将实现的编译器)。 所以,如果一个协议有一个方法func doSomething()->String你需要实际上编写这个方法在你自己的类中,以便你的类符合协议。

7

你可能有这样的旧版本的功能paymentQueue的:

func paymentQueue(queue: SKPaymentQueue, updatedTransactions transactions: [AnyObject]) {... } 

这个功能,现在可以声明如下:

func paymentQueue(queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {... } 

的productRequest应申报如下:

func productsRequest (request: SKProductsRequest, didReceiveResponse response: SKProductsResponse) {... } 

这是因为你必须实现这个方法来符合协议l

相关问题