Ios 视图控制器不符合SKPaymentTransactionObserver、SKProductsRequestDelegate的协议

Ios 视图控制器不符合SKPaymentTransactionObserver、SKProductsRequestDelegate的协议,ios,swift,view,controller,Ios,Swift,View,Controller,我正在尝试将托管内容添加为单个视图应用程序的IAP。然而,在编码时,我在Xcode 7中不断遇到以下错误 视图控制器不符合SKPaymentTransactionObserver、SKProductsRequestDelegate的协议 这是代码 import UIKit import StoreKit class ViewController: UIViewController, SKPaymentTransactionObserver, SKProductsRequestDelegate

我正在尝试将托管内容添加为单个视图应用程序的IAP。然而,在编码时,我在Xcode 7中不断遇到以下错误

视图控制器不符合SKPaymentTransactionObserver、SKProductsRequestDelegate的协议

这是代码

import UIKit
import StoreKit

class ViewController: UIViewController, SKPaymentTransactionObserver, SKProductsRequestDelegate {   

    @IBOutlet weak var lblQuotes: UILabel!

    @IBOutlet weak var btnAnotherQuote: UIButton!

    @IBOutlet weak var btnRemoveAds: UIButton!

    @IBOutlet weak var btnGetTheGuide: UIButton!

    @IBOutlet weak var btnRestore: UIButton!


    var quoteArray = ["Coming together is a beginning; keeping together is progress; working together is success...Henry Ford","Success is not final, failure is not fatal...Winston Churchill", "It is no use saying, 'We are doing our best...You have got to succeed in doing what is necessary...Winston Churchill", "The price of success is hard work, dedication to the job at hand....Vince Lombardi","Failure is not an option. Everyone has to succeed...Arnold Schwarzenegger","Happiness lies in the joy of achievement and the thrill of creative effort...Franklin D. Roosevelt","Success is a lousy teacher. It seduces smart people into thinking they can't lose...Bill Gates","Frustration, although quite painful at times, is a very positive and essential part of success.","There is little success where there is little laughter...Andrew Carnegie","Success is not forever and failure isn't fatal...Don Shula", "Success is getting what you want. Happiness is wanting what you get.","The secret of my success is a two word answer: Know people...Harvey S. Firestone","Formal education will make you a living; self-education will make you a fortune...Jim Rohn","When love and skill work together, expect a masterpiece...John Ruskin","If you have no critics you'll likely have no success...Malcolm X","The ladder of success is best climbed by stepping on the rungs of opportunity.","There is only one success - to be able to spend your life in your own way...Christopher Morley","There is no success without hardship...Sophocles","Success is dependent on effort...Sophocles","As kids we're not taught how to deal with success; we're taught how to deal with failure...Charlie Sheen","Success isn't a result of spontaneous combustion. You must set yourself on fire...Arnold H. Glasow","Success is a state of mind. If you want success, start thinking of yourself as a success...Joyce Brothers","Strive not to be a success, but rather to be of value...Albert Einstein","Eighty percent of success is showing up...Woody Allen","Success is achieved and maintained by those who try and keep trying...W. Clement Stone","Success is not measured by what you accomplish, but by the opposition you have encountered...Orision Swett Marden","Success comes from knowing that you did your best to become the best that you are capable of becoming...John Wooden","Formula for success: rise early, work hard, strike oil...J. Paul Getty","It would be wonderful to enjoy success without seeing envy in the eyes of those around you.","If everyone is moving forward together, then success takes care of itself...Henry Ford","A person needs their difficulties to enjoy success.","Success depends upon previous preparation, and without such preparation there is sure to be failure...Confucius","Success is simple. Do what's right, the right way, at the right time...Arnold H. Glasow","The foundation stones for a balanced success are honesty, character, integrity, faith, love and loyalty...Zig Ziglar","No man succeeds without a good woman behind him. Wife or mother, if it is both, he is twice blessed indeed...Godfret Winn","All you need in this life is ignorance and confidence, and then success is sure...Mark Twain","Success is finding satisfaction in giving a little more than you take...Christpher Reeve","Try not to become a person of success, but rather try to become a person of value...Albert Einstein","Success consists of going from failure to failure without loss of enthusiasm...Winston Church","Success is how high you bounce when you hit bottom...George S.Patton","Desire is the key to motivation, but it's determination and,commitment to an unrelenting pursuit of your goal.","Don't aim for success if you want it; just do what you love and believe in, and it will come naturally...David Frost","The starting point of all achievement is desire...Napolean Hill","Success is nothing more than Schwarzenegger few simple disciplines, practiced every day...","If you love what you are doing, you will be successful."]

    var numberQuote = 40
    var buttonTextArray = ["Start Your Journey","Success Inspiration","Get It Done!","Not Trying Is Failing"," Much effort, Much prosperity.","Know You Can Do It.","Focus","Persistence","Failure is Part Of Learning.","Be Time Wealthy.","Everyone has to succeed.","Failure is not an option.","Determination","Time Rich","Have A Winning Day","Be Happy","Go For It!","Be The Tiger","Stick To It!","Don't Stress","Work Hard","Love Yourself!","Be Awesome!","Think Positive","Reach Your Goals","Dream It!","Believe It","Achieve It!","Carry On","Be Fearless","Make The Moment","Enjoy The Ride","Inspire Others","Stay Positive","Take Risks","Keep Moving Forward","Always Believe","Stay Ready","Love Others","Enhance Lives","Be Inspirational","Be Healthly","Be Helpful","Live Well"]

    var numberButton = 40
    var  numberCheck = 0

    var product: SKProduct!       

    override func viewDidLoad() {
        super.viewDidLoad()            
    }

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

    @IBAction func btnRestore(sender: UIButton) {
    }       

    @IBAction func btnGetTheGuide(sender: UIButton) {
        let payment:SKPayment = SKPayment(product: product)
        SKPaymentQueue.defaultQueue().addPayment(payment)
    }

    @IBAction func btnemoveAds(sender: UIButton) {
    }

    @IBAction func btnAnoterQuoteACTION(sender: UIButton) {
        selectQuote()
        changeButtonText ()
     }

    func selectQuote() {            
        numberQuote = Int(arc4random_uniform(40))

        if numberQuote == numberCheck{
            numberQuote = Int(arc4random_uniform(40))

            if numberQuote == numberCheck && numberQuote != 0{
                numberQuote = 0
            }
            else{
                numberQuote = 1
                }
    }
        printQuote()            
    }

    func printQuote(){            
        lblQuotes.text = "\(quoteArray[numberQuote])"            
    }

    func changeButtonText(){            
        numberButton = Int(arc4random_uniform(3))
        btnAnotherQuote.setTitle("\(buttonTextArray[numberQuote])", forState: UIControlState.Normal)
    }
}

那么如何解决这个问题呢?

实现SKPaymentTransactionObserver和SKProductsRequestDelegate的协议方法

参考

对于SKPaymentTransactionObserver

对于SKProductsRequestDelegate:

注意: 还有很多东西是遗漏的,所以你也可以遵循一个非常好的教程;

编辑: 在类中实现以下两个必需的方法将删除该错误

func productsRequest(request: SKProductsRequest, didReceiveResponse response: SKProductsResponse) {
    //Code here   
}

func paymentQueue(queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
     //Code here  
}

非常感谢Shoaib我将回顾这些链接。我确实看了教程,但可以通过错误。嗨,Shoaib,即使在输入了所需的代码之后,我仍然会收到错误。@KyleRansom,可以制作一个具有相同问题的示例代码并与我共享,以便我可以看到问题吗?