iAD implementation using self.canDisplayBannerAds = YES; - ios

After watching an Apple WWDC video I decided to implement iAd using
#import iAd
...
self.canDisplayBannerAds = YES;
which has been nice and simple and it displays test ads both in the simulator and on device. The Apple vid I saw said that's all we have to do, but the Apple iAd doc site says we have to implement delegate methods to handle tapping, failing to load, network connectivity issues and that Apps that don't do so will be rejected.
That strikes me as confusing, not least because the implementation above doesn't add a protocol to the class so that the delegate methods can be implemented.
Does anyone know where the up to date docs are that implement iAds this new way ? Or know authoritatively that we have to ignore what was said in the Vid and implement the delegate methods (though would they even be called?)?

I had the same issue. There doesn't appear to be a way to assign a delegate unless you use the old method (which defeats the purpose). My specific issue was an error I was getting when on another screen without Ads, which said that I wasn't handling the didFailToReceiveAdWithError and hadn't set a delegate. To fix this specific issue I simply enabled and disabled ads as the view appeared and disappeared. Like so:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear: animated];
// Setup iAd Banner Ads
self.canDisplayBannerAds = YES;
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear: animated];
// Disable iAd Banner Ads
self.canDisplayBannerAds = NO;
}

Related

Does clicking an iOS iAd pause new ads from being fetched?

When an iAd banner is clicked, and the interactive ad doesn't leave the app, are ads still received by the app while the full screen ad is displayed? Or is receiving new ads suspended at this time?
It doesn't say either way in Apple's docs.
I ask because I want to give the app every chance to optimize the CTR (click-through rate), so I'm wondering if I should stop ads manually like this:
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner
willLeaveApplication:(BOOL)willLeave {
if(!willLeave) {
[self destroyAdBanner]; // to stop receiving new ads
}
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self createAdBanner]; // start receiving new ads again if not already
}
What is the official approach? An Apple reference would be greatly appreciated.
There is no official documentation that I can find, but from repeated trials after an ad banner is clicked and the full-screen ad appears and waiting for long periods of time, there are no further calls to any of the ad delegate methods until the user interaction terminates. It looks like no new ads are fetched while in user interaction mode.

iOS equivalent to Android registerActivityLifecycleCallbacks

I developed an Android app where I used the application.registerActivityLifecycleCallbacks (http://developer.android.com/reference/android/app/Application.html) to know when each Activity is started and stopped and record it for analytics purposes. I am now developing the iOS version and I cannot find an equivalent to this method to monitor the UIViewControllers or UIView displayed by the app.
Anybody has an idea ? I am a beginner on iOS so I may not be taking the right approach, feel free to suggest other ideas.
Edit
After the first answer I felt I should be more precise.
I am actually developing a SDK for other developers to include in their apps so I want the impact of the SDK on their code to be as small as possible.
I first thought about doing a BaseActivity/BaseUIViewController that developers would have to extend in all the Activity/UIViewController but it felt heavy and since both language don't allow multiple inheritance this would greatly impact their code. This is why the registerActivityLifecycleCallbacks method is great in Android because they only have to give me an Application or Activity object.
Is there a solution for iOS or I will have to create a BaseController ?
Thank you in advance.
I've not run into anything that specific as the application.registerActivityLifecycleCallbacks in iOS, but you could always implement your own using the methods that exist within the AppDelegate and each class.
From the AppDelegate, you are provided the methods to determine the state of the overall application such as determining when the application finished loading, when it enters the background, and so forth. Details on these states can be found in the UIApplicationDelegate Protocol Reference page.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
NSLog("Application did finish launching with options: %#", launchOptions);
return YES;
}
For each view controller, you can add your implementation to the individual view controller lifecycle methods within each file. Methods such as viewDidLoad, viewWillAppear, viewDidAppear, and viewDidLayoutSubviews are available.
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(#"View %# did load", self);
}

Flurry ads integration using SDK 6.0 creates performance issue app crashes

Hi I am using latest flurry SDK 6.0 in app. I need to show ads almost every where in my app. App is UINavigationControllerBased contains more viewControllers. I am using code given in flurry documentation.
I am using below code in each and every ViewController but some times I move fast just like push and pop before add received,so in that case callbacks are continuously receiving but that viewcontroller is not available in stack at that time app crash or recieve memory. I tried to set adDelegate to nil in viewWillDisappear but flurry documentation says don't set it as nil.
Anyone has any ideas regarading this?
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if(self.adBanner == nil){
self.adBanner = [[FlurryAdBanner alloc] initWithSpace:#"Flurry Banner"] ;
self.adBanner.adDelegate = self;
[self.adBanner fetchAndDisplayAdInView:self.view viewControllerForPresentation:self];
}
}
Perhaps you should split the code in two?
Fetch the Ad using fetchAdForFrame. This prevents Flurry from using the view you passed.
Then inside the delegate, use displayAdInView. Only call this if you know the view is visible. So in viewWillAppear set a flag to say visible, in viewWillDisappear set a flag to say not visible. This should let you cut off the rendering part.
Seems odd an API like this would have no cancelFetchAd method!

How to stop GADBannerView/MPAdView from getting ads?

I am using the 2 mediation for ads.
When IAP is purchased, I want to remove the ad banner.
Right now I use removeFromSuperview to remove the views. However, the ads are still being refreshed. How do I stop getting more ads?
You also should probably release the GADBannerView as well as nil out your delegate. So if you do something like:
adBanner_.delegate = nil;
// Don't release if you're using ARC.
[adBanner_ release];
Of course this assumes you don't want to add the GADBannerView again at some point later in your application flow.
I guess its
[adBanner_ stopAutomaticallyRefreshingContents];
And I think its better to add the delegate nilling to (as RajPara suggested).

ads in universal app + ad persisting even when viewController changes

I'm implementing ads for the first time in an app that will be universal. I've followed a few tutorials and sorta|kinda have it working - using adWhirl, iAd, adMob. The tutorials were a bit simplistic though and I'm wondering if there are any open source universal ad template/library projects out there.
I've seen this and while helpful, the tutorial code is kind of broken/limited.
The specific questions I have (iOS5+ universal app):
In an app with a navController where the UIViewController can segue
multiple times to other controllers and then back again, do I need to
set up the ad stuff in each viewController or is there some way I
can have the ad layer/view persist across multiple VC views?
Ad sizes - In my test app, running on iPad I am getting ads but the
size is for iPhone. In adWhirl it didn't seem possible to specify
universal - only iPhone or Android. I've seen other iPad apps that seem to have a problem presenting ads because of the size - ads
appear in weird places, etc. Is there some universal solution to
the issue of ad sizes in universal apps?
For your first question, I would recommend that you use a singleton approach for your adView. You can find a similar singleton approach for an AdMob adView here. Tweaking that with your AdWhirl view instead shouldn't be bad at all. For each view that is displayed then, you could just do something like:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
shared = [AdWhirlMasterViewController singleton];
[shared resetAdView:self];
}
For your second question, I wonder if you can't just make some minor modifications to your adapter code to get iPad ads to show. So, for example, for AdMob adapter's getAd: method, you'd probably have something that looks like:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
adSize = kGADAdSizeLeaderboard;
} else {
adSize = kGADAdSizeBanner;
}
Then create your GADBannerView doing something similar to:
GADBannerView *view =
[[GADBannerView alloc] initWithAdSize:adSize];

Resources