chrisjp / CJPAdController

A singleton class providing a simple way to add iAd and AdMob ads to a view controller. Choose one as the default, fall back to the other.
http://chrisphillips.co.uk
MIT License
202 stars 58 forks source link

Tabview Controller #1

Closed GuitarKevinS closed 11 years ago

GuitarKevinS commented 12 years ago

I can't get this to work in a tab view. I have CJPAdController in all the view controllers. When the app starts the screen is blank and nothing happens until I click on the second tab. I then go back to first tab view and it will then display with the ad. I'm a newbie so maybe I'm doing something wrong. Great work by the way. I learned a lot by studying the code.

chrisjp commented 12 years ago

Unfortunately I haven't had time to test it within a TabBarController. Worth noting that sometimes ad requests can take a while to actually be received and appear, they're not always instant. Perhaps this is simply the case here? It's also possible that the ad is in fact being received, but being positioned behind the tab bar so you don't see it.

I'm actually in the process of completely rewriting the code to make it a lot faster and more efficient, as well as retaining the ad view between views. Again it's designed to be used in a NavigationController but once I've finished I'll look into seeing if I can add more flexibility to it to make it play nicely with TabBars.

If you're not urgently wanting to release your app, I'd recommend waiting until I've pushed an update to this. Hopefully shouldn't take too long, I aim to have it finished within a week or so.

GuitarKevinS commented 12 years ago

I don't think the ad is behind the tab bar because the whole container view is blank. It's like the view controller within in the first tab is getting hung up when the application starts. I then can click on the second tab and everything will display. If I go back to the first tab it will display as well. I think I don't understand enough about tab bar controllers yet to figure out the problem. I can wait for the update though. I look forward to checking it out. This is the first time I used a singleton before.

chrisjp commented 12 years ago

Just pushed the 1.3 update. I haven't had chance to test this with a tab bar yet, but you might find this works better with it. Let me know if it's still not working though, now I've got this update out I can look to making it more flexible and test it in different view controllers.

TCSFrank commented 11 years ago

this stuff is awesome! i'm using tabbed views so I probably won't be customizing this myself, but I look forward to a tabbed version of this. VERY nice work.

chrisjp commented 11 years ago

It's recommended that you display ads at the top of the view when using a UITabBarController, Apple (and most ad providers) don't like publishers placing ads in close proximity to buttons (like the TabBar itself) that a user might press due to the obvious risk of accidental clicks. Anyway, I just modified the AppDelegate in the demo project to use code like this...

UIViewController *viewController1 = [[RootViewController alloc] init];
UIViewController *viewController2 = [[AnotherExample alloc] init];
_tabController = [[UITabBarController alloc] init];
_tabController.viewControllers = @[viewController1, viewController2];
_adController = [[CJPAdController sharedManager] initWithContentViewController:_tabController];

self.window.rootViewController = _adController;

... and it seems to work as you might expect, albeit without a UINavigationBar. Ads were positioned correctly at the top of the view and remained there when selecting the other tab. Rotating the device also worked correctly. I made no modifications to my CJPAdController class, all seemed to be working fine as it is.

I'm fairly certain there won't be any major issues implementing CJPAdController in a real TabBar application with all your views set up correctly, but if there are then let me know and I'll see if I need to modify some of the code.

TCSFrank commented 11 years ago

Works perfectly (slightly modified for storyboard). Got any advice on how to get this to persist in modal views, or am I trying to do the impossible?

morismoris commented 11 years ago

I have a universal TabBar application (with Storyboard).

One big trouble: iAd banner works perfectly, but adMob banner never appears. I did several tests:

So the problem is in my app, but where?

In my AppDelegate:didFinishLaunchingWithOptions:

UITabBarController tabBarController = (UITabBarController )self.window.rootViewController; _adController = [[CJPAdController sharedManager] initWithContentViewController:tabBarController]; self.window.rootViewController = _adController;

chrisjp commented 11 years ago

That's a strange one, I don't even recall seeing that error when testing. That said, I don't have a real TabBar app to test it in, but a quick modification of my AppDelegate like so (as I similarly did in response to the original issue here):

UIViewController *viewController1 = [[RootViewController alloc] init];
UIViewController *viewController2 = [[AnotherExample alloc] init];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = @[viewController1, viewController2];
_adController = [[CJPAdController sharedManager] initWithContentViewController:tabBarController];

self.window.rootViewController = _adController;

...and it appears to work just fine with both iAd and AdMob.

I did a quick Google search for the error and couldn't really find much that seems to be relevant. Someone in this thread on the AdMob SDK group had this problem when subclassing his views, are you doing anything like that in your app?

morismoris commented 11 years ago

Found! It was the user agent overrided in a scene of storyboard, once I commented this out, ads started showing... I have also subclassing of UITableViewController, but does not seem influential.

Still does not work if I try to use the Ad Network Mediation of adMob with: static BOOL const kUseiAd = NO; static BOOL const kUseAdMob = YES; but this problem is a little problem, I could always handle the choice between iad/adMob depending on the country from inside your code.

Il giorno 11/apr/2013, alle ore 02:53, Chris Phillips notifications@github.com ha scritto:

That's a strange one, I don't even recall seeing that error when testing. That said, I don't have a real TabBar app to test it in, but a quick modification of my AppDelegate like so (as I similarly did in response to the original issue here):

UIViewController viewController1 = [[RootViewController alloc] init]; UIViewController viewController2 = [[AnotherExample alloc] init]; UITabBarController *tabBarController = [[UITabBarController alloc] init]; tabBarController.viewControllers = @[viewController1, viewController2]; _adController = [[CJPAdController sharedManager] initWithContentViewController:tabBarController];

self.window.rootViewController = _adController; ...and it appears to work just fine with both iAd and AdMob.

I did a quick Google search for the error and couldn't really find much that seems to be relevant. Someone in this thread on the AdMob SDK group had this problem when subclassing his views, are you doing anything like that in your app?

— Reply to this email directly or view it on GitHub.