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];
Related
iOS 9.3, Xcode 7.3, ARC enabled.
I am migrating away from iAd, and I have some general questions regarding best design patterns and how to properly use the Google Mobile Ads framework for banner style ads.
How do you control presentation on ad load and load failure?
My typical approach is to start with the banner view hidden, detect when the ad is loaded, then either animate the banner view in from the top or bottom, or fade in from a stand-in image.
I noticed that GADBannerView class, does not have some of the more convenient properties of an iAd banner, such as isLoaded.
a) Right now I take advantage of the two methods - (void)adViewDidReceiveAd:(GADBannerView *)bannerView and - (void)adView:(GADBannerView *)bannerView didFailToReceiveAdWithError:(GADRequestError *)error, set an instance variable bool for the view controller when either method gets a message, then use that variable for any additional UI changes else where. Is this a good design practice?
b) "deleted", animation works.
c) When the ad fails to load, what happens to the banner view? I notice that its alpha property is still 1.0 and that it is not hidden. In a production environment when an AdMob ad fails to load, is the banner clear? Or does it have a generic stand-in image? In other words, am I going to have to slide in an image to balance the view without the banner view there?
I've read from the basic AdMob tutorial that it doesn't really matter where the banner is, it can be in multiple view controllers, the framework will manage how these multiple banners will be filled. Could someone confirm this behavior? Say, I have two view controllers and I have two different banner views, I don't have to manage the ads? All I have to do is provide the banner view real estate?
Generally speaking, if I used to have iAd for ads and also in-app. purchases through iTunes, then what is the modern day trend? Am I supposed to have ads through AdMob and keep in-app. purchases as they are through Apple? Is that what people are doing now?
Thanks in advance for your answers. I know this maybe too general, but I really want some sort of a fundamental understanding where to head, before I submit anything to Apple.
--
Here is the code for animation I am using:
- (void)adViewDidReceiveAd:(GADBannerView *)bannerView
{
bannerDidLoad = true;
[UIView animateWithDuration:1.0 animations:^{
bannerView.alpha = 1.0;
bannerView.frame = CGRectMake(bannerView.frame.origin.x, bannerView.frame.size.height, bannerView.frame.size.width, bannerView.frame.size.height);
} completion:^(BOOL finished) {
nil;
}];
}
You should really narrow your question down. It's kind of vague. Anyways, yes GADBannerView's will be clear if they fail to receive an ad. Using the delegate methods to know what state the GADBannerView is in is the standard. Animating the alpha property should not be an issue. Not really sure what that last question is asking. You can use any ad network you'd like. If you're using in app purchases already just continue using them and remove the GADBannerView instead of the ADBannerView.
I am creating an iOS8+ application and am ready to add iAd to it. At this time, I've set the following in viewDidLoad() for each UIViewController in my application:
self.canDisplayBannerAds = true
Everything seems to be working properly... Ads are appearing when I switch between views. Is this the proper way to enable iAd with multiple views on iOS8 and newer releases?
I have not found any documentation that says how to use canDisplayBannerAds with multiple view controllers. I found a lot of postings for earlier releases of iOS where the developer had to implement iAd on his/her own, and only create a singleton. Anyway, I hope that someone can verify that what I have done is correct and will work properly when the app goes to the store.
Thank you for your time and help,
Mike
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;
}
I have an app idea, but I'm not sure if it's possible.
I was wondering if I'm able to display one thing on the iPad ( or iPhone )
screen, and something totally different on the Apple Tv at the same time.
For example, a quiz app, where the question is displayed on the Apple Tv, and the multiple choices are listed on the iPad for the user to pick.
I'm not sure if this is possible or if you can only Mirror the iPad screen onto the Apple Tv.
If there is some "Proof of Concept" example code, I'd love to take a look.
Thank you so much.
Chris
Turns out that is is pretty simple to support two screens: the primary screen of the iOS device and a secondary screen (either an external display or mirroring on an Apple TV).
Based on information from the blog post Creating a Dual-Screen AirPlay Experience for iOS and Apple TV, you don't need to do much.
Basically you need to check the screens property from UIScreen. There are also notifications you should listen for (UIScreenDidConnectNotification and UIScreenDidDisconnectNotification) so you know if the number of screens changes while your app is running.
Once you have a second screen, you need to create a new window for it. Code like the following can be used:
if ([UIScreen screens].count > 1) {
if (!_secondWin) {
UIScreen *screen = [UIScreen screens][1];
_secondWin = [[UIWindow alloc] initWithFrame:screen.bounds];
_secondWin.screen = screen;
}
}
where _secondWin is a UIWindow ivar.
Once the window is setup, create a view controller, make it the window's root view controller, and show the window:
SomeViewController *vc = [[SomeViewController alloc] init...];
_secondWin.rootViewController = vc;
_secondWin.hidden = NO;
This is pretty much it other than proper handling of the notifications. Keep in mind that you can't get any touch events on the 2nd display so make sure whatever you show is basically display-only.
Depending on your app, you might have the 2nd screen/window being used throughout the lifetime of the app (as long as the 2nd screen is available any way). Or you might only create and use the 2nd window/screen under certain circumstances. When you don't setup the 2nd window/screen, your app will simply be mirrored to the 2nd display or Apple TV.
The last piece is to turn on mirroring to the Apple TV. This is done on the iOS device, not in the app.
The blog post I linked has a few more details worth reviewing.
In the view programming guide for iOS, it states "Every iOS application needs at least one window—an instance of the UIWindow class—and some may include more than one window."
What are some examples Apps that would need more than one window?
Thanks
Apps that require to output video to a second screen might use more than one window.
Here you have a question about that particular topic.
You could also use more than one window to achieve other objectives, but that is not recommended by Apple. In general if you see that you need 2 windows or more, I'd suggest that something is wrong with your approach.
I've played around with 2 windows to integrate cocos2d and uikit in a test project, the code was pretty clean and the idea was to switch between windows, using the visibility and the key window, as necessary. It worked, but sometimes when sending the app to background, for some magical reason the active, key window would be made invisible.
Afaik the only case you'd need more than one window is if you connect another screen like a TV to your device. In that case you could provide a totally independent UI for the second screen. F.e. the Keynotes app on iPad does that when you connect another screen to the device.
You could register for the UIScreenDidConnectNotification and handle it like this:
- (void)screenDidChange:(NSNotification *)notification
{
if ([UIScreen screens] count] > 1)
{
UIScreen *extScreen = [[UIScreen screens] objectAtIndex:1];
UIWindow *extWindow = [[UIWindow alloc] initWithFrame:[extScreen bounds]];
//add some subviews to the window
extWindow.screen = extScreen;
[extWindow makeKeyAndVisible];
}
}