gpt4 book ai didi

ios - ViewController 类型不符合 SKPaymentTransactionObserver 协议(protocol)

转载 作者:行者123 更新时间:2023-11-30 13:50:53 26 4
gpt4 key购买 nike

即使输入所需的代码后,我仍然收到错误消息。我缺少什么?

class ViewController: UIViewController, SKPaymentTransactionObserver, SKProductsRequestDelegate, GADBannerViewDelegate {
@IBOutlet weak var txtYearlyIncome: UITextField!
@IBOutlet weak var sldPercentSaved: UISlider!
@IBOutlet weak var lblPercent: UILabel!
@IBOutlet weak var lblWeeklySaved: UILabel!
@IBOutlet weak var lblMonthlySaved: UILabel!
@IBOutlet weak var lblYearlySaved: UILabel!
@IBOutlet weak var lblSaved25: UILabel!
@IBOutlet weak var btnRemoveAds: UIButton!
@IBOutlet weak var bannerView: GADBannerView!
@IBOutlet weak var lblAdsRemoved: UILabel!

var yearlyIncomeString = ""
var yearlyIncomeFloat : Float = 0.0
var percent : Float = 0.0
var weeklySaved : Float = 0.0
var MonthlySaved : Float = 0.0
var YearlySaved : Float = 0.0
var Saved25 : Float = 0.0
var decimalValue : Float = 0.0
var product: SKProduct!

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.bannerView.adUnitID = "ca-app-pub-3042973809533220/1135061595"
self.bannerView.rootViewController = self

let request : GADRequest = GADRequest ()

self.bannerView.loadRequest (request)
self.bannerView.hidden = true
self.bannerView.delegate = self
btnRemoveAds.hidden = true
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func productsRequest(request: SKProductsRequest, didReceiveResponse response: SKProductsResponse) {
let products = response.products
if (products.count != 0)
{
product = products[0] as SKProduct
}

btnRemoveAds.hidden = true

if (NSUserDefaults.standardUserDefaults().objectForKey("Ads") == nil)
{
SKPaymentQueue.defaultQueue().addTransactionObserver(self)
self.getProductInfo();
}

if let status: AnyObject! = NSUserDefaults.standardUserDefaults().objectForKey("Ads"){
if status as! NSString == "purchased" {
self.bannerView.removeFromSuperview()
self.btnRemoveAds.hidden = true;
self.btnRemoveAds.userInteractionEnabled = false
}
else {
SKPaymentQueue.defaultQueue().addTransactionObserver(self)
self.getProductInfo()
}
}
}

func getProductInfo(){
if SKPaymentQueue.canMakePayments(){
let productID:NSSet = NSSet(object:"smmremoveads")
let request:SKProductsRequest = SKProductsRequest(productIdentifiers: productID as! Set<String>)
request.delegate = self
request.start()
}

func paymentQueue(queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]){
for transaction:AnyObject in transactions {
if let trans:SKPaymentTransaction = transaction as? SKPaymentTransaction{
switch trans.transactionState {
case .Purchased:
SKPaymentQueue.defaultQueue().finishTransaction(transaction as! SKPaymentTransaction)
storePurchase()
lblAdsRemoved.text = "Ads Removed!"
break
case .Failed:
SKPaymentQueue.defaultQueue().finishTransaction(transaction as! SKPaymentTransaction)
break
case .Restored:
SKPaymentQueue.defaultQueue().restoreCompletedTransactions()
break
default:
break
}
}
}
}

func storePurchase () {
NSUserDefaults.standardUserDefaults().setObject("purchased", forKey: "Ads")
self.bannerView.removeFromSuperview()
self.btnRemoveAds.hidden = true
self.btnRemoveAds.enabled = false
lblAdsRemoved.text = "Ads Removed"
}
}

@IBAction func sldPercentSavedACTION(sender: UISlider) {
takeINData()
calculate()
}

@IBAction func btnRemoveAdsACTION(sender: UIButton) {
}

@IBAction func btnClearACTION(sender: UIButton) {
clear()
}

func takeINData () {
if txtYearlyIncome.text == ""{
txtYearlyIncome.text = "10000"
}

yearlyIncomeString = txtYearlyIncome.text!
yearlyIncomeFloat = Float(yearlyIncomeString)!
percent = sldPercentSaved.value
}

func calculate () {
YearlySaved = yearlyIncomeFloat * percent
MonthlySaved = YearlySaved / 12
weeklySaved = YearlySaved / 52
Saved25 = YearlySaved * 25
print()
}

func print () {
percent = percent * 100

let sPercent = String(format: "%0.0f", percent)
let sWeekly = String(format: "%0.0f", weeklySaved)
let sMonthly = String(format: "%0.0f", MonthlySaved)
let sYearly = String(format: "%0.0f", YearlySaved)
let sSaved25 = String(format: "%0.0f", Saved25)

lblPercent.text! = "\(sPercent)%"
lblWeeklySaved.text = "$\(sWeekly)"
lblMonthlySaved.text = "$\(sMonthly)"
lblYearlySaved.text! = "$\(sYearly)"
lblSaved25.text = "$\(sSaved25)"
}

func clear () {
txtYearlyIncome.text! = ""
lblWeeklySaved.text = "$"
lblMonthlySaved.text = "$"
lblYearlySaved.text! = "$"
lblSaved25.text = "$"

lblPercent.text! = "0%"
}

func hideKeyboard () {
txtYearlyIncome.resignFirstResponder()
}

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
hideKeyboard()
}

func round () {

}
}

最佳答案

在我看来,您好像缺少右大括号,但很难判断,因为您的代码格式很差(我会立即为您解决这个问题!)

问题出在这里:

func getProductInfo() {
if SKPaymentQueue.canMakePayments() {
let productID:NSSet = NSSet(object:"smmremoveads")
let request:SKProductsRequest = SKProductsRequest(productIdentifiers: productID as! Set<String>)
request.delegate = self
request.start()
}

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

请注意 getProductInfo 如何打开两个大括号 ({) 并仅关闭一个大括号?这就是问题所在:在 func paymentQueue 之前需要第二个 }。

关于ios - ViewController 类型不符合 SKPaymentTransactionObserver 协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34298735/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com