view controller does not conform to protocol for SKPaymentTransactionObserver, SKProductsRequestDelegate

I am trying to add hosted content as an IAP for a single view app. However when coding I keep getting the following errors in Xcode 7

"view controller does not conform to protocol for SKPaymentTransactionObserver, SKProductsRequestDelegate"

Here is the code.

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)
    }
}

So how can I resolve this issue?

Answers


Implement the protocol methods of SKPaymentTransactionObserver and SKProductsRequestDelegate

Ref.

for SKPaymentTransactionObserver https://developer.apple.com/library/prerelease/ios/documentation/StoreKit/Reference/SKPaymentTransactionObserver_Protocol/index.html

for SKProductsRequestDelegate: https://developer.apple.com/library/prerelease/ios/documentation/StoreKit/Reference/SKProductsRequestDelegate/index.html

Note: There are many more things which are missing so you may follow a very good tutorial too; http://www.raywenderlich.com/105365/in-app-purchases-tutorial-getting-started

Edit: Implementing following 2 required methods in your class will remove the error.

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

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

Need Your Help

Throw an exception or return null

java exception coding-style null

If I've got the function below, with two choices

How do i consuming rest service with jquery in phonegap

javascript jquery ajax rest monaca

I am using monaca IDE + phonegap to build a phone app.