2015-11-30 38 views
1

我想添加託管內容作爲一個單一的視圖應用程序的IAP。然而編碼我不斷收到在Xcode 7視圖控制器不符合協議SKPaymentTransactionObserver,SKProductsRequestDelegate

以下錯誤時,「視圖控制器不符合協議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) 
    } 
} 

那麼我該如何解決這個問題呢?

回答

3

實施SKPaymentTransactionObserver和SKProductsRequestDelegate

Ref的協議方法。

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

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

注: 還有更多的東西丟失,所以你可以遵循一個很好的教程太多; http://www.raywenderlich.com/105365/in-app-purchases-tutorial-getting-started

編輯: 實現以下在2種所需的方法將刪除錯誤。

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

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

非常感謝Shoaib我會檢查這些鏈接。我沒有看教程,但可以通過錯誤。 –

+0

我已經更新了答案,所以請查看。 – Shoaib

+0

嗨Shoaib即使在輸入所需的代碼後,我仍然得到他的錯誤。 –

相關問題