2014-04-09 13 views
2

我一直在研究我的第一個應用程序幾個月,並且在我將它發送到應用程序商店之前需要添加廣告的階段。我已經成功添加了iAD,並試圖配置Chartboost。如何在AppDelegate類中返回YES到BOOL?

我試圖阻止Chartboost在我的遊戲的某些部分顯示插頁式廣告時遇到問題。我已經設置了位置按文檔的Chartboost網站和Chartboost.h文件,它的狀態:

// Return NO if showing an interstitial is currently inappropriate, for example if the user has entered the main game mode 
- (BOOL)shouldDisplayInterstitial:(NSString *)location; 

很抱歉,如果這聽起來像一個愚蠢的問題,但我已經通過我的書的iOS和網上搜索對於我肯定的答案很簡單。如何從其他課程返回YES(BOOL)shouldDisplayInterstitial。 I.E從我的GameViewController.m?

+0

逸岸這個方法應該返回YES或NO,而期望一個字符串作爲參數。 –

回答

0

如何從其他課程返回YES/No?

1.Delegate很重要。設置Chartboost的委託給你的GameViewController類

Chartboost *cb = [Chartboost sharedChartboost]; 
cb.delegate = self;//Specify your GameViewController object instead of self; 

2.implement方法在您的類

- (BOOL)shouldDisplayInterstitial:(NSString *)location 
{ 
    return YES; 
} 

最佳實踐:Source

首先運行經驗

這很好 練習(並在iOS人機界面指南中註明)僅在用戶第一次玩遊戲後才顯示插頁式廣告。

您可以使用下面Chartboost SDK的委託方法,以防止插頁廣告,直到第二startSession:

- (BOOL)shouldRequestInterstitialsInFirstSession { 
    return NO; 
} 

參考這個例子

https://github.com/ChartBoost/client-examples/blob/master/iOS/ChartboostExample/ExampleAppAppDelegate.m

Chartboost in iphone project/Chartboost usage in iOS

+0

似乎沒有任何示例說明如何在遊戲中的某個部分(從不同的類)返回NO到應用程序委託中的(BOOL)shouldDisplayInterstitial。你知道任何關於github嗎? –

+0

我找不到你的問題 –

+0

Hello @ Vijay-Apple-Dev.blogspot.com我發現瞭如何去做。以下是示例代碼:[link](https://gist.github.com/DanielTomlinson/8a59a9cd64a911a0f3a4)在Appdelegate中創建一個VOID方法,並使用該方法將返回值傳遞給BOOL方法。工作過一種享受! –

0

1)您創建了一個Chartboost對象併爲其設置了一個委託。

Chartboost *cb = [Chartboost sharedChartboost]; 
cb.delegate = self; 

2)自如果需要實現shouldDisplayInterstitial方法的委託

- (BOOL)shouldDisplayInterstitial:(NSString *)location 
{ 
    return YES; 
} 

example project here

+0

所以在我的GameViewController中,我想返回NO到shouldDisplayInterstitial:我應該調用CB委託,然後將NO或FALSE發送到AppDelegate中的BOOL。我將如何構造這個?我假設的是這樣的:[cb shouldDisplayInterstitial(NO)]; ? –

0

通過委託。如果你需要聲明shouldDisplayInterstitial:類不能回答這個問題,應該問一個類,它可以:

- (BOOL) shouldDisplayInterstitial: (NSString *)location 
{ 
    return [self.delegate shouldDisplayInterstitial:location]; 
} 

你代表應符合特定的協議和實現方法。

關於代表團的更多信息請登錄here