我是iAd Xcode开发的新手。我创建了一个Xcode应用程序' BasicBannerView'对于iAd横幅。我运行了该应用程序,并收到了消息'您已连接到iAd'但是当我点击横幅时,我收到了消息' Leave' BasicBannerView'并在Safari中打开此链接?'访问此网站将导致您离开该应用程序。
如何在应用程序中看到横幅?
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//init BannerView object and Set Delegate
_bannerView = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];
_bannerView.delegate = self;
//Set banner property AutoSize
[_bannerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[self.view addSubview:_bannerView];
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self bannerCheck:NO];
//ADBannerView *adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 50, 320, 50)];
//[self.view addSubview:adView];
_adBanner = [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, 320, 50)];
_adBanner.delegate = self;
}
//called Automatically when ad is available
-(void) bannerViewDidLoadAd:(ADBannerView *)banner
{
_bannerViewDidLoadAdCount +=1;
[self updateCountLabels];
[self bannerCheck:YES];
}
// Called automatically when user taps on the advert
-(BOOL) bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
_bannerViewActionShouldBeginCount += 1;
[self updateCountLabels];
[self PauseAppFunctionality];
return YES;
}
// Called when user finishes with advert and close the ad
-(void)bannerViewActionDidFinish:(ADBannerView *)banner
{
_bannerViewActionDidFinishCount += 1;
[self updateCountLabels];
[self ContiuneAppFunctionality];
}
// Called when there is an error displaying Advert
-(void) bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
_bannerViewDidFailToReceiveAdWithErrorCount += 1;
[self updateCountLabels];
[self bannerCheck:YES];
}
-(void) updateCountLabels
{
self.bannerViewDidLoadAdCountLabel.text = [NSString stringWithFormat:@"%d",_bannerViewDidLoadAdCount];
self.bannerViewActionShouldBeginCountLabel.text = [NSString stringWithFormat:@"%d",_bannerViewActionShouldBeginCount];
self.bannerViewActionDidFinishCountLabel.text = [NSString stringWithFormat:@"%d",_bannerViewActionDidFinishCount];
self.bannerViewDidFailToReceivedAdWithErrorCountLabel.text = [NSString stringWithFormat:@"%d",_bannerViewDidFailToReceiveAdWithErrorCount];
}
-(void) bannerCheck:(BOOL)animated
{
// Get Frame
CGRect contentFrame = self.view.bounds;
CGRect bannerFrame = _bannerView.frame;
// if there is ad available show ad view else hide
if(_bannerView.bannerLoaded) {
bannerFrame.origin.y = contentFrame.size.height - bannerFrame.size.height;
}
else {
bannerFrame.origin.y = contentFrame.size.height;
}
// animate ad on or off the screen
[UIView animateWithDuration:animated?0.20:0.0 animations:^{_bannerView.frame = bannerFrame;}];
}
-(void)cancelAd
{
// How to cancel displayed ad:avoid if you can
if(_bannerView.bannerViewActionInProgress) {
[_bannerView cancelBannerViewAction];
}
}