我一直收到错误消息(类型'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()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func dimissView(_ sender: Any) {
self.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
}
}
}
}
}