我开发了一个最近获得苹果批准的应用程序。但问题是 iAd 没有在 iphone 中显示,而 ipad iAd 显示完美。在开发时,iAd 已加载并在 iPhone 和 iPad 上进行测试广告。但是在获得苹果的批准后,我从商店下载了应用程序,注意到 iAd 没有加载到 iphone 中,但它正在加载到 ipad 中。我在其他应用程序中检查了 iphone 中的其他应用程序 iAd 工作正常,但在我的应用程序中 iAd 没有加载。那么我现在应该怎么做才能在 iphone 中加载 iAd。
我在应用程序中使用的代码是
-(void)showiAdInView
{
if (!appDelegate.isUpgraded) {
bannerView = [[ADBannerView alloc] init];
bannerView.delegate = self;
bannerView.backgroundColor = [UIColor colorWithWhite:1.0f alpha:0.005f];
bannerView.hidden = TRUE;
bannerIsVisible = FALSE;
[self.view addSubview:bannerView];
}
}
-(void)bannerViewDidLoadAd:(ADBannerView *)banner
{
bannerIsVisible = YES;
bannerView.hidden = FALSE;
NSLog(@"ADBanner is Showing");
[self bannerViewShow];
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
bannerIsVisible = FALSE;
bannerView.hidden = TRUE;
NSLog(@"ADBanner is Hidding");
NSLog(@"%@",[error description]);
[self bannerViewHide];
}
-(BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication: (BOOL)willLeave
{
if ([self.captureSession isRunning]) {
[self.captureSession stopRunning];
iAdLoaded = TRUE;
}
return YES;
}
-(void)bannerViewActionDidFinish:(ADBannerView *)banner
{
UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
[self willRotateToInterfaceOrientation:interfaceOrientation duration:0.2f];
if (![self.captureSession isRunning] && iAdLoaded) {
[self.captureSession startRunning];
iAdLoaded = FALSE;
}
}
-(void)bannerViewShow
{
[bannerView setBackgroundColor:[UIColor colorWithWhite:1.0f alpha:0.005f]];
UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[MsgtextView setFrame:MsgTextVwAdBannerFrame];
[UIView commitAnimations];
adBannerFrame = CGRectMake(0, 190, 320, 50);
clearButton.frame = CGRectMake(ClearButtonFramePotrait.origin.x, ClearButtonFramePotrait.origin.y, ClearButtonFramePotrait.size.width, ClearButtonFramePotrait.size.height);
[self.view bringSubviewToFront:bannerView];
[bannerView setFrame:adBannerFrame];
[bannerView setCurrentContentSizeIdentifier:ADBannerContentSizeIdentifierPortrait];
}
else if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[MsgtextView setFrame:CGRectMake(MsgTextVwAdBannerFrame.origin.x, MsgTextVwAdBannerFrame.origin.y, MsgTextVwAdBannerFrame.size.width, MsgTextVwAdBannerFrame.size.height+8)];
[UIView commitAnimations];
adBannerFrame = CGRectMake(0, 105, 470, 32);
clearButton.frame = CGRectMake(ClearButtonFrameLandscape.origin.x, ClearButtonFrameLandscape.origin.y, ClearButtonFrameLandscape.size.width, ClearButtonFrameLandscape.size.height);
[bannerView setCurrentContentSizeIdentifier:ADBannerContentSizeIdentifierLandscape];
[self.view bringSubviewToFront:bannerView];
[bannerView setFrame:adBannerFrame];
}
}
else if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[MsgtextView setFrame:MsgTextVwAdBannerFrame];
[UIView commitAnimations];
adBannerFrame = CGRectMake(0, 640, 768, 50);
[bannerView setCurrentContentSizeIdentifier:ADBannerContentSizeIdentifierPortrait];
clearButton.frame = CGRectMake(ClearButtonFrame_iPadPotrait.origin.x, ClearButtonFrame_iPadPotrait.origin.y, ClearButtonFrame_iPadPotrait.size.width, ClearButtonFrame_iPadPotrait.size.height);
[self.view bringSubviewToFront:bannerView];
[bannerView setFrame:adBannerFrame];
}
else if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[MsgtextView setFrame:CGRectMake(MsgTextVwAdBannerFrame.origin.x, MsgTextVwAdBannerFrame.origin.y, MsgTextVwAdBannerFrame.size.width, MsgTextVwAdBannerFrame.size.height+8)];
[UIView commitAnimations];
adBannerFrame = CGRectMake(0, 325, 1024, 32);
[bannerView setCurrentContentSizeIdentifier:ADBannerContentSizeIdentifierLandscape];
clearButton.frame = CGRectMake(ClearButtonFrame_iPadPotrait.origin.x, ClearButtonFrame_iPadPotrait.origin.y, ClearButtonFrame_iPadPotrait.size.width, ClearButtonFrame_iPadPotrait.size.height);
[self.view bringSubviewToFront:bannerView];
[bannerView setFrame:adBannerFrame];
}
}
}
-(void)bannerViewHide
{
[bannerView setBackgroundColor:[UIColor clearColor]];
UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[MsgtextView setFrame:MsgTextVwFrame];
clearButton.frame = ClearButtonFramePotrait;
[bannerView setHidden:YES];
[UIView commitAnimations];
}
else if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[MsgtextView setFrame:MsgTextVwFrame];
clearButton.frame = ClearButtonFrameLandscape;
[bannerView setHidden:YES];
[UIView commitAnimations];
}
}
else if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[MsgtextView setFrame:MsgTextVwFrame];
clearButton.frame = ClearButtonFrame_iPadPotrait;
[bannerView setHidden:YES];
[UIView commitAnimations];
}
else if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[MsgtextView setFrame:MsgTextVwFrame];
clearButton.frame = ClearButtonFrame_iPadPotrait;
[bannerView setHidden:YES];
[UIView commitAnimations];
}
}
}