How to implement admob on view controller? - iphone

In my app, I want to implement admob and now only I have started to learn about it. So any one please guide me and is there any nice tutorial or sample?

It's extremely simple. Follow the guide here: http://developer.admob.com/wiki/IPhone#AdMob_iPhone_SDK
Once you have the SDK up, you simply do:
AdMobView *ad = [AdMobView requestAdWithDelegate:<your delegate>]; // start a new ad request
ad.frame = CGRectMake(0, 432, 320, 48); // set the frame, in this case at the bottom of the screen
[self.window addSubview:ad]; // attach the ad to the view hierarchy; self.window is responsible for retaining the ad

Download the Admob SDK for iPhone and look at the example projects. It's very simple.

If you choose to use the Interface Builder approach and follow their steps
there is one step missing: Add an AdViewController object to your UIViewController.h/m file and use that as the referencing object in IB. Otherwise you'll get the error:
"Must implement required method
-currentViewControllerForAd:(AdMobView *)adView in your delegate"
I realize this is a basic assumption, but it caught me for a minute and i've implemented AdMob 3 times in the past (using different methods, mind you).
Add an ad to a view using Interface Builder
Add AdViewController.h and AdViewController.m to your project (located in the IBSupport subdirectory).
Open Interface Builder.
Place a 320x48 UIView where you want the ad to appear.
Add an Object, and change its type to AdViewController.
Set the view outlet of the AdViewController to your UIView.
Set the currentViewController outlet of the AdViewController
to the UIViewController owning the xib.
Edit AdViewController.m to make sure that your publisher ID and
other options are set correctly.

Good thing to know, Mike. They also left out one step in Interface Builder. You need to select File's Owner, and drag from Ad View Controller to the new Ad View Object. I simply cannot comprehend why Admob would leave out these details, especially when many new programmers join they're community all the time. They really need help in the documentation & tutorials department.

Related

How to share a iAd adbanner across view's?

I am making a iPhone app, I am currently using iAd's in my view's. I've read something about apple recommending to share the adbanner's through out the view's. How can i do this because I have read the apple documentation and it was not clear enough and i was confused, please help me, if their are any tutorials please tell me or just answer and point me in the right way. Currently I have a ad for every view controller and it runs nice but it comes with a error: Too many active banners (10). Creation of new banners will be throttled.
Please help, i am using storyboards and the latest Xcode :) thanks
The way I do it is use a Singleton class that creates the adView, this way you only ever get 1 adView. Then in your viewDidAppear methods of all your ViewControllers you simply add the adView to your view.
You can see my code in the accepted answer here although that is for an AdWhirl ad view, it shouldn't be too difficult to change it for an iAd ad view.
This is the perfect case for a singleton. Many have simply made a subclass of ADBannerView, which can then be added to your view in -viewDidLoad (or -viewDidAppear with the proper precautions taken) and removed in -viewDidDisappear for each View Controller.

tabbed application with adwhirl using storyboard

I've tabbed application with storyboard. I want to have adwhirl below my tabbar. Though I'm customising my tabbar after clicking out at any item.I'm not able to change the position of tabbar at initial stage. And I also want my all tabbarviewcontrollers are of custom size, so that after inApp purchase the adwhirl will be removed and entire tabbarviewcontoller will resize again to its original position.Any idea how to achieve this.FYI I want to have adwhirl with iAd & adMob
get Apple's iAdSuite , and look at TabbedBanner and SplitViewBanner . you'll have to combine some effects from the two. the SplitViewBanner will show you how to embed another view-controller inside the BannerViewController, nesting viewControllers. i think the TabBarBanner code puts the ad "above" the tab-bar, but you can see how the tab-bar controller is created on the fly. if you combine the two concepts, you can probably get what you want.
additionally, while the examples are with these items on the fly, i was able to create a splitViewController in storyboard, and then re-set the rootViewController to be the bannerViewController containing the tabBarController.
might look something like this (again, assuming you've created the tabBarController in storyboard):
UITabBarController* tabBarController = (id)self.window.rootViewController;
CGRect tabBarViewFrame = TabBarController.view.frame;
tabBarViewFrame.origin.y -= application.statusBarFrame.size.height;
tabBarViewFrame.size.height += application.statusBarFrame.size.height;
tabBarController.view.frame = tabBarViewFrame;
// get BannerViewController from the SplitViewBanner of iAdSuite ;
// it should do the work of creating the space for your iAds only when necessary.
self.bannerViewController
= [[BannerViewController alloc] initWithContentViewController:tabBarController];
self.window.rootViewController = self.bannerViewController;
After so many researches I found that with Adwhirl this is not possible. This could be only possible if I want my AdMob & iAd at different places. And since I want my both ads at the same place with different time period . I can't achieve this in this way. So I did it in other way. In which I've taken an Extra UIView. Which will be added when I don't want ads. And will be removed when I need it. And instead of adding it below tabbar. I've integrated ads above tabbar. Thus I've fullfilled my requirement with some stitches.

Return to mainview from webView deployed using storyboard

I created a new project "Single View Application" and designed the mainView with Storyboard. My main view contains a UIButton that opens the camera, the camera scans barcode and automatically goes to a website. Now I created a webView programmatically so that website can open and also created a UIButton inside the webView. Now I want that UIButton to act as home botton and return to mainview. I am unable to do that, please help.
ViewController.m code: http://cl.ly/FKj8
My storyboard looks like:
You really should look into the View Controller Programming Guide -- by switching around the contents of a single view controller, you're making a lot of extra work for yourself with little benefit. By using multiple view controllers when you want to have different "screens" in your app, you can take advantage of storyboarding for easier development, and you automatically get better memory management (read: less potential for crashes), too.
However, to more directly answer your question... if you're putting the WebView into the view hierarchy with [self.view addSubview:webView], you can remove it with [webView removeFromSuperview]. (This means you'll have to keep a reference to the WebView around so you can refer to it when you want to dismiss it.)
I also noticed in the code you posted to cl.ly an unrelated method -deviceModel which uses uname() to get device information. This is a bad idea, for two reasons:
uname() isn't guaranteed to do something useful on an iOS device (even if it currently does). Use the UIDevice class instead if you need this kind of info, or...
Generally, you don't want to test for the device name to enable functionality in your app; instead, you should test for the capabilities you need. (For example, if you look for a device name starting with "iPhone 4" to test for a Retina display, you'll miss the 4th-generation iPod touch, and the iPhone-5-or-whatever-they-call-what's-next. Instead, use the UIScreen class.)

How to generate .m/.h files from Storyboard?

Is there a convenient way to generate code from any new view controllers I've created on the storyboard? For example when you create a new iOS application, XCode will set up a skeleton class for your view controller.
Thanks!
I don't think so. You need to create a new ViewController subclass in XCode but uncheck the "Create Xib for this class" box (not sure if that is exactly what it says). Then select your newly made view controller in storyboard and change it to the class you just created.
Ok the skeleton you are talking about is just a template for your application. You are asking for a dynamic template generator from your storyboard and maybe Apple can figure out how to do this in a non distant future but in this moment I think you can't do that. After you created the storyboard file with your complex scheme you need to manually create all your viewController subclass you used in the storyboard. It's not a big deal ... I suppose your application doesn't have thousand ViewController so you can do it manually.
Apple are working hard to simplify developers job but Xcode can't do everything for you.
You can try to post this answer directly to Apple throughout the bugreport Apple website and post it as improvement to implement in future Xcode release.
Lets try it :)

How to get/set the rootViewController?

Now,I gonna Develop an App ,which wants to switch from many different Views irregularly,also the views need to load large resources,AKA,it's hard to manage memory.Are there any good solustion?
PS:I created a ViewController as RootViewController,and When a button was Touch,run the code as
"ViewController=newController"
.The problem came,The new View loaded wrong way,it rotate so that couldn't show in a correct way.
I google for the solution,some one said ,I should replace the rootViewController,just like that,
[UIApplication sharedApplication].delegate.window.rootViewController=newController;
But I can't get/set the rootViewController in other class though it's a singleton.
Why not having a class that handles all the view switches ?
This article describes an architecture that might be helpfull: http://www.mikeziray.com/2010/01/27/handling-your-initial-view-controllers-for-iphone/comment-page-1/#comment-607