Question

I have been working on my first app for a few months and am at the stage where I need to add advertising before I send it to the App store. I have added iAD successfully and am trying to configure Chartboost.

I run into problems when I try to stop Chartboost from showing Interstitials at certain parts of my game. I have set up locations as per the documentation on the Chartboost website and in the Chartboost.h file it states:

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

Sorry if this sounds like a silly question but I've been searching through my iOS book and online for the answer which I'm sure is simple. How do I return YES to (BOOL)shouldDisplayInterstitial from another class. I.E from my GameViewController.m ?

Was it helpful?

Solution

How do i return that YES/No from other class?

1.Delegate is matter. Set delegate of Chartboost to your GameViewController class

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

2.implement the method in your class

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

Best Practices: Source

First run experience

It's good practice (and noted in the iOS Human Interface Guidelines) to show interstitials only after the user has played your game for the first time.

You can use the below Chartboost SDK delegate method to prevent interstitials until the second startSession:

- (BOOL)shouldRequestInterstitialsInFirstSession {
    return NO;
}

Refer this example

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

Chartboost in iphone project / Chartboost usage in iOS

OTHER TIPS

Through delegation. If the class where you need to declare shouldDisplayInterstitial: cannot answer the question, it should ask a class that can:

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

Your delegate should conform to a specific protocol and implement the method.

More on delegation can be found here.

1) You created a Chartboost object and set a delegate to it.

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

2) Self if a delegate that needs to implement shouldDisplayInterstitial method

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

See example project here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top