Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ios中的Admob显示问题_Ios_Objective C_Admob - Fatal编程技术网

ios中的Admob显示问题

ios中的Admob显示问题,ios,objective-c,admob,Ios,Objective C,Admob,我正在开发一个集成admob的应用程序。我已经给出了我的广告单元和应用程序Id,但广告没有显示。这是我在appdelegate中编写的代码 [GADMobileAds configureWithApplicationID:@"ca-app-pub-6419920332120857~7417324780"]; 这是我在VC课上写的代码 //Admob Banner bannerView_ = [[GADBannerView alloc]initWithFrame:CGRectMake(0, 2

我正在开发一个集成admob的应用程序。我已经给出了我的广告单元和应用程序Id,但广告没有显示。这是我在appdelegate中编写的代码

 [GADMobileAds configureWithApplicationID:@"ca-app-pub-6419920332120857~7417324780"];
这是我在VC课上写的代码

//Admob Banner
bannerView_ = [[GADBannerView alloc]initWithFrame:CGRectMake(0, 20, 320, 70)];
NSLog(@"%@",bannerView_);
bannerView_.adUnitID = @"ca-app-pub-6419920332120857/8171578220";
GADRequest *request = [GADRequest request];
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
[bannerView_ loadRequest:[GADRequest request]];

request.testDevices = @[ @"326e918015806f8d65a43e86f9e6e939" ];

NSLog(@"%@",request);

试试这段代码我对你的代码做了一些修改

#import <GoogleMobileAds/GoogleMobileAds.h>

@interface ViewController ()<GADBannerViewDelegate>
{

}

@property(nonatomic, strong) GADBannerView *bannerView;

@end

@implementation ViewController
@synthesize bannerView;

- (void)viewDidLoad {
    [super viewDidLoad];

    bannerView = [[GADBannerView alloc]initWithFrame:CGRectMake(0, 20, [UIScreen mainScreen].bounds.size.width, 70)];
    bannerView.adUnitID = @"ca-app-pub-3940256099942544/2934735716"; //change this key
    GADRequest *request = [GADRequest request];
    //request.testDevices = @[ @"326e918015806f8d65a43e86f9e6e939" ];
    request.testDevices = @[ kGADSimulatorID ];
    bannerView.rootViewController = self;
    bannerView.delegate = self;
    [self.view addSubview:bannerView];
    [bannerView loadRequest:request];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/// Tells the delegate an ad request loaded an ad.
- (void)adViewDidReceiveAd:(GADBannerView *)adView {
    NSLog(@"adViewDidReceiveAd");
}

/// Tells the delegate an ad request failed.
- (void)adView:(GADBannerView *)adView
didFailToReceiveAdWithError:(GADRequestError *)error {
    NSLog(@"adView:didFailToReceiveAdWithError: %@", [error localizedDescription]);
}

/// Tells the delegate that a full-screen view will be presented in response
/// to the user clicking on an ad.
- (void)adViewWillPresentScreen:(GADBannerView *)adView {
    NSLog(@"adViewWillPresentScreen");
}

/// Tells the delegate that the full-screen view will be dismissed.
- (void)adViewWillDismissScreen:(GADBannerView *)adView {
    NSLog(@"adViewWillDismissScreen");
}

/// Tells the delegate that the full-screen view has been dismissed.
- (void)adViewDidDismissScreen:(GADBannerView *)adView {
    NSLog(@"adViewDidDismissScreen");
}

/// Tells the delegate that a user click will open another app (such as
/// the App Store), backgrounding the current app.
- (void)adViewWillLeaveApplication:(GADBannerView *)adView {
    NSLog(@"adViewWillLeaveApplication");
}
#导入
@界面视图控制器()
{
}
@属性(非原子,强)GadbanerView*bannerView;
@结束
@实现视图控制器
@综合横幅视图;
-(无效)viewDidLoad{
[超级视图下载];
bannerView=[[GADBannerView alloc]initWithFrame:CGRectMake(0,20[UIScreen mainScreen].bounds.size.width,70)];
bannerView.adUnitID=@“ca-app-pub-3940256099942544/2934735716”;//更改此键
GADRequest*请求=[GADRequest请求];
//request.testDevices=@[@“326e918015806f8d65a43e86f9e6e939”];
request.testDevices=@[kgadsimulatid];
bannerView.rootViewController=self;
bannerView.delegate=self;
[self.view addSubview:bannerView];
[bannerView加载请求:请求];
}
-(无效)未收到记忆警告{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
///告诉代理加载了ad的ad请求。
-(无效)adViewDidReceiveAd:(GADBannerView*)adView{
NSLog(@“adViewDidReceiveAd”);
}
///告诉代理ad请求失败。
-(void)adView:(GADBannerView*)adView
DidFailtReceiveAvithError:(GADRequestError*)错误{
NSLog(@“adView:DidFailToReceiveAvithError:%@,[error localizedDescription]);
}
///告知学员将显示全屏视图作为响应
///给点击广告的用户。
-(无效)adViewWillPresentScreen:(GadbanerView*)adView{
NSLog(@“adViewWillPresentScreen”);
}
///告诉学员全屏视图将被取消。
-(无效)adViewWillDismissScreen:(GadbanerView*)adView{
NSLog(@“adViewWillDismissScreen”);
}
///告诉学员全屏视图已取消。
-(无效)AdviewIDDismissScreen:(GadbanerView*)adView{
NSLog(@“adViewDidDismissScreen”);
}
///告诉代理用户单击将打开另一个应用程序(例如
///应用商店),对当前应用进行后台处理。
-(作废)adViewWillLeaveApplication:(GadbanerView*)adView{
NSLog(@“adViewWillLeaveApplication”);
}
安装pod以便于集成
pod“谷歌移动广告SDK”

[卡扎菲] 配置应用程序ID:@“ca-app-pub-6419920332120857~7417324780”]

您需要按如下方式更改此代码

[卡扎菲] 配置应用程序ID:@“ca-app-pub-6419920332120857/7417324780”]

~无法从新的实施中工作。 您还可以在仿真器中作为测试设备检查测试广告,如下所示

request.testDevices=[UIDevice.current.IdentifierFor供应商?? “”,“您的模拟器id”]


您是否尝试签入真实设备?在代码中您可能会犯一些小错误,我无法测试它,但只需替换为我的代码并再次测试以检查此链接上的解决方案:我在测试广告上测试过它,它显示给我的广告很好,但当我在真实设备上运行时,它不会显示任何广告。@RAHUL H KAMBADI在测试广告上测试过它,它显示给我的广告很好,但当我在真实设备上运行时,它不会显示任何广告显示任何广告。@Hardik Thakkarit只是显示测试广告,我想在我的应用程序上显示实时广告@Hardik Thakkary您需要为此创建应用程序并将应用程序与admob帐户链接,请参考联机文档,您将获得相关步骤。使用上述委托方法检查登录真实设备,如果配置中存在错误,它将打印,放置断点并检查是的,我得到了,并将其我的应用程序名称放在Appstore上@哈迪克·塔卡尔