2012-06-06 2 views
-4
#pragma mark - iAd method. 


/*Starts:iAd*/ 

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 

    Class cls = NSClassFromString(@"ADBannerView"); 
    if(cls!=nil) 
    { 
     [self layoutForCurrentOrientation:YES]; 
    } 

} 

-(void)createADBannerView 
{ 

    NSString *contentSize = UIInterfaceOrientationIsPortrait(self.interfaceOrientation) ? ADBannerContentSizeIdentifierPortrait : ADBannerContentSizeIdentifierPortrait; 

    CGRect frame; 
    frame.size = [ADBannerView sizeFromBannerContentSizeIdentifier:contentSize]; 
    frame.origin = CGPointMake(0.0, CGRectGetMaxY(self.view.bounds)); 


    // Now to create and configure the banner view 
    ADBannerView *bannerView = [[ADBannerView alloc] initWithFrame:frame]; 
    // Set the delegate to self, so that we are notified of ad responses. 
    bannerView.delegate = self; 
    // Set the autoresizing mask so that the banner is pinned to the bottom 
    bannerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin; 
    bannerView.requiredContentSizeIdentifiers = [NSSet setWithObjects:ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierPortrait, nil]; 

    // At this point the ad banner is now be visible and looking for an ad. 
    [self.view addSubview:bannerView]; 
    self.banner = bannerView; 
    [bannerView release]; 
} 


-(void)layoutForCurrentOrientation:(BOOL)animated 
{ 

    CGFloat animationDuration = animated ? 0.2 : 0.0; 
    // by default content consumes the entire view area 
    CGRect contentFrame = self.view.bounds; 
    CGPoint bannerOrigin = CGPointMake(CGRectGetMinX(contentFrame), CGRectGetMaxY(contentFrame)); 
    CGFloat bannerHeight = 0.0; 

    banner.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait; 
    bannerHeight = 55.0; 

    if(banner.bannerLoaded) 
    { 
     contentFrame.size.height -= bannerHeight; 
     bannerOrigin.y -= bannerHeight; 
    } 
    else 
    { 
     bannerOrigin.y += bannerHeight; 
    } 

    // And finally animate the changes, running layout for the content view if required. 

    NSLog(@"[UIApplication sharedApplication].statusBarOrientation = %d",[UIApplication sharedApplication].statusBarOrientation); 



    [UIView animateWithDuration:animationDuration 
        animations:^{ 
         contentView.frame = contentFrame; 
         [contentView layoutIfNeeded]; 

         banner.frame = CGRectMake(0,361, banner.frame.size.width, banner.frame.size.height); 
        }]; 
} 


/*Ends:iAd*/ 

/*Starts:Added By:CP.Date:26-Dec-2010. 
AdMob methods*/ 

#pragma mark - AdMobDelegate methods 

-(NSString *) publisherIdForAd:(AdMobView *)adView 

{ 

    return @"a14f91029b8c719"; // this should be prefilled; if not, get it from www.admob.com 
} 

-(UIViewController *) currentViewControllerForAd:(AdMobView *)adView 
{ 

    return self; 
} 

-(UIColor *)adBackgroundColorForAd:(AdMobView *)adView 
{ 

    return [UIColor colorWithRed:0 green:0 blue:0 alpha:1]; // this should be prefilled; if not, provide a UIColor 
} 

-(UIColor *)primaryTextColorForAd:(AdMobView *)adView 
{ 

    return [UIColor colorWithRed:1 green:1 blue:1 alpha:1]; // this should be prefilled; if not, provide a UIColor 
} 

-(UIColor *)secondaryTextColorForAd:(AdMobView *)adView 
{ 

    return [UIColor colorWithRed:1 green:1 blue:1 alpha:1]; // this should be prefilled; if not, provide a UIColor 
} 

-(void) didReceiveAd:(AdMobView *)adView 
{ 

    adMobAd.frame = CGRectMake(0,361,320,55); 

    //adMobAd = [AdMobView requestAdOfSize:ADMOB_SIZE_748x110 withDelegate:self]; 
    [self.view addSubview:adMobAd]; 
} 

// Sent when an ad request failed to load an ad 

-(void)didFailToReceiveAd:(AdMobView *)adView 
{ 

    Class cls = NSClassFromString(@"ADBannerView"); 
    if(cls!=nil) 
    { 
     if(banner == nil) 
     { 
      [self createADBannerView]; 
     } 
     [self layoutForCurrentOrientation:NO]; 
    } 

    [adMobAd removeFromSuperview]; // Not necessary since never added to a view, but doesn't hurt and is good practice 
    [adMobAd release]; 
    adMobAd = nil; 
    // we could start a new ad request here, but in the interests of the user's battery life, let's not 
} 

/*Ends:Added By:CP.Date:26-Dec-2010. 
AdMob methods*/ 
+0

Вы можете оставить некоторые изображения баннера IAD/AdMob? – Jasmit

+0

А также сообщение viewDidLoad. – Jasmit

+0

} else { \t [adMobAd removeFromSuperview]; } } –

ответ

1

Прежде всего, ясность о iad или admob, которые представляют собой две разные формы для перемещения в приложении. Я думаю, вы пытаетесь интегрировать admob adv. вам необходимо выполнить следующие шаги.

http://www.edumobile.org/iphone/iphone-programming-tutorials/how-to-admob-integrate-in-your-application-in-iphone/

Смежные вопросы