如何显示iAD?

时间:2014-02-05 11:49:54

标签: ios iphone iad

我使用以下代码显示iAD

  bannerView = [[ADBannerView alloc]initWithFrame:
              CGRectMake(0, 0, 320, 50)];
// Optional to set background color to clear color
bannerView.delegate=self;
[bannerView setBackgroundColor:[UIColor clearColor]];
[self.view addSubview: bannerView];}

iAd未显示在模拟器中。每次调用以下委托方法

-(void)bannerView:(ADBannerView *)bannerdidFailToReceiveAdWithError:(NSError *)error{
NSLog(@"Error loading %@",error);}

1 个答案:

答案 0 :(得分:1)

您好您可以按照以下步骤进行iAd

Add Delegate OF banner view
<ADBannerViewDelegate>

//Set Property
@property(nonatomic, strong) ADBannerView *bannerView;


viewDidLoad
//*************** ADBannerView ***********
     bannerView = [[ADBannerView alloc]
     init];
     bannerView.delegate = self;
     [bannerView setBackgroundColor:[UIColor clearColor]];
     //***********************************************




//*********************** For iAd ***************************
 - (void)bannerViewDidLoadAd:(ADBannerView *)banner
{

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
 {
     bannerView.frame = CGRectMake(0, self.view.frame.size.height-66, 750, 80);
 }
 else
 {
    if ([[UIScreen mainScreen] bounds].size.height == 568)
    {
        if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending){


            bannerView.frame = CGRectMake(0, self.view.frame.size.height-110, 320, 50);

        }else{

            bannerView.frame = CGRectMake(0, self.view.frame.size.height-50, 320, 50);
        }
    }else{

        if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending){
            bannerView.frame = CGRectMake(0, self.view.frame.size.height-50, 320, 50);
        }else{
            bannerView.frame = CGRectMake(0, self.view.frame.size.height-50, 320, 50);
        }
    }
 }
     [self.view addSubview:bannerView];
     [self.view bringSubviewToFront:bannerView];
}

- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave{
     return YES;
}

 - (void)bannerViewActionDidFinish:(ADBannerView *)banner
{
    if ([[UIScreen mainScreen] bounds].size.height == 568) {}else{}
}

-(void)bannerView:(ADBannerView *)banner
 didFailToReceiveAdWithError:(NSError *)error
{
}

由于