我爲我的iOS應用程序使用SpriteKit,並且需要一些全屏(或有時稱爲「插頁式」iAds,以便每隔一段時間彈出一次。我可以找出代碼的發生時間,但我需要知道添加iAds,而不必改變視圖控制器。SpriteKit中的Interstitial iAds?
我嘗試了TechTopia的[教程] [1]關於Interstitial iAds,但要做到這一點,我需要在實際的視圖控制器之間進行切換。在GameViewController.m中的代碼表示它最初設置爲我的遊戲的主菜單(SKScene),所以當我嘗試從遊戲中轉換回到GameViewController時,它將它搞砸了。 iAd,而不是保持相同的SKScene,它進入我的主菜單場景。
我需要這些問題的答案:
- 是否有某種方式以外的其他使用兩個視圖控制器,顯示間質性網絡成癮?
- 如果不是,我該如何解決這個問題?
- 如果我要將我的「非頁內iAds」更改爲「前貼片視頻iAds」,也會出現此問題嗎?
-
編輯!編輯!編輯!編輯!編輯!編輯!編輯!編輯!編輯!編輯!編輯!編輯!編輯!編輯!
-
我最終決定使用crashoverride777的答案,並創建一個Objective-C橋接報給他的銀行代碼轉換成Objective-C的。但是當引用Ads.swift
的變量presentingViewController
時,它最終爲零。這裏是我的代碼在GameViewController.m
:
// Set up interstitial iAds.
Ads *adsClass = [[Ads alloc] init];
Ads *adsInstance = [Ads sharedInstance];
adsInstance.presentingViewController = self;
然而,這並沒有做任何事情。功能從我的GameScene.m
被調用,就像它應該的那樣,但是沒有廣告出現。在我的Ads.swift
中,我添加了一個日誌來查看presentingViewController
是否確實爲零。
print("iAd inter showing")
if (self.presentingViewController != nil) {
print("presentingViewController != nil")
iAdInterAdView.frame = presentingViewController.view.bounds
presentingViewController.view.addSubview(iAdInterAdView)
iAdInterAd!.presentInView(iAdInterAdView)
UIViewController.prepareInterstitialAds()
iAdInterAdView.addSubview(iAdInterAdCloseButton)
} else {
print("presentingViewController == nil")
}
日誌出來每次都是這樣:「presentingViewController ==無」。我不確定發生了什麼問題,在這裏。
翻譯:'iAdInterAdCloseButton = [UIButton的buttonWithType:UIButtonTypeSystem]'和'如果([的UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)' –
爲什麼會引起你的麻煩?第一個按鈕代碼是swift 2.0中的新功能,因爲它之前在swift中略有不同。在對象C中,它應該看起來像這樣我認爲UIButton * iAdInterAdCloseButton = [UIButton buttonWithType:UIButtonTypeSystem]; – crashoverride777
關於設備代碼。你的應用是通用的嗎?否則,據我所知,它不會被調用?你可以閱讀這個,並嘗試檢查設備是否是iPad的可能方法http://stackoverflow.com/questions/10167221/ios-detect-if-user-is-on-an-ipad – crashoverride777