How can one implement iAd in such manner that it is implemented in only AppDelegate and can be used in all screens.
I put code in appDelegate.Do i still need to code for it in each view controller?
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self addiAd];
NSLog(@"window subview : %@",self.window.subviews); //Here it shows no subview
return YES;
}
-(void)addiAd
{
self.adView.delegate = self;
self.adView.requiredContentSizeIdentifiers = [NSSet setWithObjects:ADBannerContentSizeIdentifierLandscape,ADBannerContentSizeIdentifierPortrait, nil];
self.adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
[self setBannerFrame:orientation];
self.adView = [[ADBannerView alloc] init];
self.adView.frame = CGRectMake(0, 938, 768, 66);
[self.window addSubview:self.adView];
}
-(void)removeiAd
{
[self.adView removeFromSuperview];
}
-(void)setBannerFrame:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
[self.adView setCurrentContentSizeIdentifier:ADBannerContentSizeIdentifierLandscape];
self.adView.frame = CGRectMake(0, 634, 320, 50);
}
else {
[self.adView setCurrentContentSizeIdentifier:ADBannerContentSizeIdentifierPortrait];
self.adView.frame = CGRectMake(0, 890, 480, 32);
}
}
All its delegate methods are also implemented in AppDelegate.m
What should be my next step? what am i doing wrong or missing?
Ya. no need to write code in each view controll. here is my code
- (UIWindow *)viewControllerForPresentingModalView {
return self;
}
- (void)adWhirlDidReceiveAd:(AdWhirlView *)adWhirlView {
NSLog(@"Ad received");
CGSize adSize = [adView actualAdSize];
NSLog(@"Net work Name %@",[adWhirlView mostRecentNetworkName]);
CGRect newFrame = adView.frame;
newFrame.size = adSize;
newFrame.origin.y=385;
NSLog(@"frame size %f,%f",newFrame.origin.x,newFrame.origin.y);
adView.frame = newFrame;
}
-(void)adWhirlDidFailToReceiveAd:(AdWhirlView *)adWhirlView usingBackup:(BOOL)yesOrNo
{
NSLog(@"Ad not Received");
NSLog(@"Net work Name %@",[adWhirlView mostRecentNetworkName]);
CGRect tempFrame = adView.frame;
tempFrame.origin.y = -adView.frame.size.height;
adView.frame = tempFrame;
}
write all this methods in app delegate and in application didFinishedLaunching method just add the adwhirl view as a sub view of the window.
adView=[AdWhirlView requestAdWhirlViewWithDelegate:self];
[self.window addSubview:adView];
Its working fine for me.