Lumpa
Lumpa

Reputation: 57

iAd on multiple view controllers

I have used iAd's before but only for apps with a single view controller. But I cannot seem to figure out how to create a global reference to the ad in the AppDelegate and fetch it from there for my separate view controllers (That's what I've read I'm supposed to do).

I've been searching for a tutorial on the matter, but for some reason I can't find anything relevant.

Any hints? Point me in the right direction? :)

TIA! /Markus

Upvotes: 0

Views: 985

Answers (1)

Shiv Kumar Singh
Shiv Kumar Singh

Reputation: 372

In applications there is a adddelegate.h and .m file. You add iad in delegate.m file and create reference in other view : in Appdelegate.h add delegate :

@interface AppDelegate : UIResponder

ADBannerView *bannerView;

@property (nonatomic, retain) ADBannerView *bannerView;

in Appdelegate.m :

@synthesize bannerView;

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

bannerView = [[ADBannerView alloc]initWithFrame:CGRectZero]; bannerView.requiredContentSizeIdentifiers = [NSSet setWithObjects:ADBannerContentSizeIdentifierLandscape,nil]; bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape; bannerView.delegate = self;

}

Now you create reference of Appdelegate in other class viewdidload :

AppDelegate *appdelegate = (AppDelegate *)[[UIApplication sharedApplication ]delegate];

UIView banner = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 480, 32)];
[banner addSubview:appdelegate.bannerView];
[self.view addSubview: banner];

Upvotes: 1

Related Questions