0

我不断收到一条错误消息(类型StoreViewController不符合协议SKPaymentTransactionObserver)我已经多次查看代码。也许我需要一套新的眼光,或者编码实际上有问题——我觉得更有可能。

我不得不在代码末尾添加一些右大括号,以将错误数量减少到一个。但在那之后,如果我尝试,它会再次上升。因此,它可能不是花括号问题。

请帮助我解决问题,或者找到我的错误。(Xcode 9.3)

import UIKit

import StoreKit

class StoreViewController: UIViewController , SKPaymentTransactionObserver , SKProductsRequestDelegate {


        @IBOutlet weak var storeLabel: UILabel!

        @IBOutlet weak var infoLabel: UILabel!

        @IBOutlet weak var buyButton: UIButton!

        @IBOutlet weak var cancelButton: UIButton!

        var product: SKProduct?

        var productID = "com.Haleemani.SilkyDragon.removeads"


        override func viewDidLoad() {
            super.viewDidLoad()

        }

        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()

        }

        @IBAction func dimissView(_ sender: Any) {
            dismiss(animated: true, completion: nil)
        }


        @IBAction func purchase(_ sender: Any) {
            let payment = SKPayment(product: product!)
            SKPaymentQueue.default().add(payment)

        }

        func getPurchaseInfo() {
            if SKPaymentQueue.canMakePayments() {

                let request = SKProductsRequest(productIdentifiers: NSSet(objects: self.productID) as! Set<String>)

                request.delegate = self
                request.start()

            } else {

                storeLabel.text = "Unsuccessful"
                infoLabel.text = "Check your settings and try again"

            }

        }

        func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
            var products = response.products
            if (products.count == 0) {

                storeLabel.text = "Unsuccessful"
                infoLabel.text = "Cheack your settings and try again"
            } else {

                product = products [0]
                storeLabel.text = product!.localizedTitle
                infoLabel.text = product!.localizedDescription
                buyButton.isEnabled = true

                let invalids = response.invalidProductIdentifiers

                for product in invalids {
                    print ("product not found: \(product)")

                }
            }
        }

        func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
            for transaction in transactions {

                switch transaction.transactionState {

                case SKPaymentTransactionState.purchased:
                    SKPaymentQueue.default().finishTransaction(transaction)
                    storeLabel.text = "Thank You"
                    infoLabel.text = "You have removed Watermark in all your images Forever"
                    buyButton.isEnabled = false

                case SKPaymentTransactionState.failed:
                        SKPaymentQueue.default().finishTransaction(transaction)
                    storeLabel.text = "Thank You"
                    infoLabel.text = "You have removed Watermark in all your images Forever"

                default:
                    break
                }
            }
        }
    }
}
4

0 回答 0