2016-09-03 16 views
1

アプリデリゲートからインタースティシャル広告を実装していて、うまく読み込んでいます。今私はそれを削除する購入ボタンが欲しい、と私は混乱しています。アプリデリゲートアプリの購入からインタースティシャル広告を削除する方法

class AppDelegate: UIResponder, UIApplicationDelegate, GADInterstitialDelegate { 

var window: UIWindow? 
var myInterstitial: GADInterstitial! 


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 


    // Override point for customization after application launch. 

    myInterstitial = createAndLoadInterstitial() 
    return true 
} 

func createAndLoadInterstitial()->GADInterstitial { 
    let interstitial = GADInterstitial(adUnitID: "xxxxx") 
    interstitial.delegate = self 

    interstitial.loadRequest(GADRequest()) 
    return interstitial 
} 

func interstitialDidReceiveAd(ad: GADInterstitial!) { 
    print("interstitialDidReceiveAd") 
} 

func interstitial(ad: GADInterstitial!, didFailToReceiveAdWithError error: GADRequestError!) { 
    print(error.localizedDescription) 
} 

func interstitialDidDismissScreen(ad: GADInterstitial!) { 
    print("interstitialDidDismissScreen") 
    myInterstitial = createAndLoadInterstitial() 
} 

とのViewController:

let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate 

override func viewWillAppear(animated: Bool) { 


    appDelegate.myInterstitial?.presentFromRootViewController(self) 

} 
+0

そして、あなたがについて混乱何ですか?本当の質問は何ですか? – Losiowaty

+0

広告を削除するにはどうすればいいですか? – Done

答えて

2

オクラホマので、本当の問題ビーイング - あなたは(コメントから)それを購入したときに広告を削除する方法

は、ここに私のコードです。

それは非常に簡単に達成することができます - あなたは購入が成功したことの確認を受け取った後、あなたは二つのことをすべき:あなたは、後続のアプリでこのことについて知ることができるようにNSUserDefaultsにフラグを

  • を設定するには、
  • を起動します

    :これ以上の広告が

は、コード例を要約すると、このセッション中に表示されませんように

  • は、nilmyInterstitialを設定しました
    func paymentComplete() { 
        NSUserDefaults.standardUserDefaults().setBool(true, forKey: "userAlreadyPaid") 
        appDelegate.myInterstitial = nil 
    } 
    

    そして、このような何かにあなたのdidFinishLaunchingWithOptionsメソッドを更新:あなたは公式ドキュメントを参照することができるアプリケーションの購入で実装する方法を学習するために

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
    
        // Override point for customization after application launch. 
        let userAlreadyPaid = NSUserDefauls.standardUserDefaults().boolForKey("userAlreadyPaid") 
    
        if !userAlreadyPaid { 
         myInterstitial = createAndLoadInterstitial() 
        } 
        return true 
    } 
    

    https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/StoreKitGuide/Introduction.html

  • +0

    'もし' userAlreadyPaid'を 'didFinishLaunchingWithOptions'の' if!userAlreadyPaid'に 'Bool'が' false'になると、 'paymentComplete()'が実行されます。 –

    +0

    あなたは完全に正しいです!私はそれをミスタイプする必要があります - ありがとう! – Losiowaty

    関連する問題