How to initiate revmob banner ad with exact frame

2019-04-02 06:34发布

I tried using the suggested code from RevMob to show a banner ad with a specific placement ID without success, tried this code:

RevMobAds *revmob = [RevMobAds revMobAds];
        RevMobBanner *banner = [revmob bannerWithPlacementId:@"ID_FROM_REV_MOB"];
        [banner showAd];

Tried even to add the following statement

if (IS_iPad) {
        banner.frame =  CGRectMake(0, 958, 768, 66);
    } else if (IS_WIDESCREEN){
        banner.frame = CGRectMake(0, 518, 320, 50);
    } else {
        banner.frame = CGRectMake(0, 430, 320, 50);
    }

but no success, the only way I could be able to show banner ads was this:

[RevMobAds showBannerAdWithFrame:CGRectMake(0, 958, 768, 66) withDelegate:self];

But it didn't help to add the placement ID.

2条回答
Melony?
2楼-- · 2019-04-02 06:50

When I'm adding it(RevMob version 5.9) in my project. I do it like this:

[RevMobAds startSessionWithAppID:@"my id"];
RevMobBannerView *ad = [[RevMobAds session] bannerView]; // you must retain this object
[ad loadWithSuccessHandler:^(RevMobBannerView *banner) {
    banner.frame = CGRectMake(0, 381, 320, 50);
    [self.window.rootViewController.view addSubview:banner];
    NSLog(@"Ad loaded");
} andLoadFailHandler:^(RevMobBannerView *banner, NSError *error) {
    NSLog(@"Ad error: %@",error);
} onClickHandler:^(RevMobBannerView *banner) {
    NSLog(@"Ad clicked");
}];
查看更多
叼着烟拽天下
3楼-- · 2019-04-02 07:03

I think you need to do it as the following by using the RevMobBannwerView instead:

RevMobAds *revmob = [RevMobAds revMobAds];
        RevMobBannerView *revBannerView = [revmob bannerViewWithPlacementId:@"ID_FROM_REV_MOB"];
        if (IS_iPad) {
            revBannerView.frame =  CGRectMake(0, 958, 768, 66);
        } else if (IS_WIDESCREEN){
            revBannerView.frame = CGRectMake(0, 518, 320, 50);
        } else {
            revBannerView.frame = CGRectMake(0, 430, 320, 50);
        }
        [revBannerView loadAd];
        [self.view addSubview:revBannerView];
        [self.view bringSubviewToFront:revBannerView];
查看更多
登录 后发表回答