开发者

how to display test IAd banner in the simulator

hi all i imported iAd frame work and implemented code for the iAd.My sample code is below shown

.h file

#import <UIKit/UIKit.h>
#import <iAd/iAd.h>

@interface IadTestViewController : UIViewController<ADBannerViewDelegate> {
BOOL isBannerVisible;
IBOutlet ADBannerView *banner;

}
@property(nonatomic,assign)BOOL isBannerVisible;
 @property(nonatomic,retain)IBOutlet ADBannerView *banner;

@end

.m file i implemented delegate methods

 #import "IadTestViewController.h"

@implementation IadTestViewController
@synthesize banner,isBannerVisible;


- (void)viewDidLoad {
[super viewDidLoad];
isBannerVisible=NO;
bannerView=[[ADBannerView alloc]initWithFrame:CGRectZero];
bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
bannerView.delegate=self;
[self.view addSubview:bannerView];

}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
 {
    if (!self.isBannerVisible)
{
    [UIView beginAnimations:@"animateAdBannerOn" context:NULL];
    // Assumes the banner view is just off the bottom of the screen.
    bannerView.frame = CGRectOffset(bannerView.frame, 0, -bannerView.frame.s开发者_Python百科ize.height);
    [UIView commitAnimations];
    self.isBannerVisible = YES;
}

}

  - (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
 { 
NSLog(@"the failed error is %@",error);
if (self.isBannerVisible)
{
    [UIView beginAnimations:@"animateAdBannerOff" context:NULL];
    // Assumes the banner view is placed at the bottom of the screen.
    bannerView.frame = CGRectOffset(bannerView.frame, 0, bannerView.frame.size.height);
    [UIView commitAnimations];
    self.isBannerVisible = NO;
}

}

And my xib connections are connected well formated.still i am not getting IAd banner in my simulator and my Log statement giving me error like this

Error Domain=ADErrorDomain Code=5 "The operation couldn’t be completed. Banner view is visible but does not have content" UserInfo=0x574fdd0 {ADInternalErrorCode=5, NSLocalizedFailureReason=Banner view is visible but does not have content}

I know iAd banner not visible when ads are zero.But i am trying to display test advertisement even that also not possible to with my program.I dont know what mistake i made or which step i forget to implement.I seen many similar questions in our stackoverflow.com but none of the answers rectify my problem.Can any one help me out from this and please provide some sample code to show the TestAdd in the simulator .Thank you in advance.

I got solution

i provided answer in the below link

Why does test iAd for barebones project not display?


Step 1:

1.import iAd Framework to the Application.

2.Provide #import in the particular controller where you want to show your Add.

3.Provide it’s delegate UIViewController

4.Provide one view to that particular ViewController.Assume I have taken

@property (weak, nonatomic) IBOutlet UIView *contentView;

Step 2:

Allocate it in ViewDidLoad method

- (void)viewDidLoad
{
_bannerView = [[ADBannerView alloc] init];
_bannerView.delegate = self;

[super viewDidLoad];
[self.view addSubview:_bannerView];
}

step 3:

Provides it’s delegate methods which i have mention bellowed.

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
} else {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
}
[self layoutAnimated:duration > 0.0];
}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
[self layoutAnimated:YES];
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
[self layoutAnimated:YES];
}

- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{

return YES;
}

- (void)bannerViewActionDidFinish:(ADBannerView *)banner
{

}
- (void)layoutAnimated:(BOOL)animated
{
if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
} else {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
}

CGRect contentFrame = self.view.bounds;
CGRect bannerFrame = _bannerView.frame;
if (_bannerView.bannerLoaded) {
contentFrame.size.height -= _bannerView.frame.size.height;
bannerFrame.origin.y = contentFrame.size.height;
} else {
bannerFrame.origin.y = contentFrame.size.height;
}

[UIView animateWithDuration:animated ? 0.25 : 0.0 animations:^{
self.contentView.frame = contentFrame;
[self.contentView layoutIfNeeded];
_bannerView.frame = bannerFrame;
}];
}

For More Detail Please refer this link


Looks like it's an issue on Apple's server side. Make sure your provisioning profile is up to date and make sure your app is registered to receive ads (through itunes connect). I can't see anything wrong with your code.

Check out this link for more.


Firstly you must check if the frame for your banner is given correctly or not.... if thats right, then may be you should check with the proxy settings in your system if you are working from office... You might need to have the download rights to download the content from internet.. This might just be one problem as you have already said that you are doing every thing else correctly...

One more thing AAAAAA.... I think you must first register with apple's iAd network through iTunes connect to receive any ads from them.... I suggest you to check their documentation on iAd's for more clarity...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜