【问题标题】:xcode6 - admob properties has previous declarationxcode6 - admob 属性有先前的声明
【发布时间】:2015-02-25 13:30:19
【问题描述】:

我想在我的项目中使用 adMob,因为 iAds interstitialAds 在我的 spriteNodes 消失后由于某种原因拉伸了它们,但我遇到了一些错误: (我已经尝试清理我的构建文件夹)

//
//  GADInterstitial.h
//  Google Mobile Ads SDK
//
//  Copyright 2011 Google Inc. All rights reserved.
//

#import <UIKit/UIKit.h>

#import <GoogleMobileAds/GADInAppPurchaseDelegate.h>
#import <GoogleMobileAds/GADInterstitialDelegate.h>
#import <GoogleMobileAds/GADRequest.h>
#import <GoogleMobileAds/GADRequestError.h>

/// An interstitial ad. This is a full-screen advertisement shown at natural transition points in
/// your application such as between game levels or news stories.
///
/// Interstitials are shown sparingly. Expect low to no fill.
@interface GADInterstitial : NSObject

#pragma mark Pre-Request

/// Required value created on the AdMob website. Create a new ad unit for every unique placement of
/// an ad in your application. Set this to the ID assigned for this placement. Ad units are
/// important for targeting and statistics.
///
/// Example AdMob ad unit ID: @"ca-app-pub-0123456789012345/0123456789"
@property(nonatomic, copy) NSString *adUnitID;

/// Optional delegate object that receives state change notifications from this GADInterstitalAd.
/// Remember to nil this property before deallocating the delegate.
@property(nonatomic, weak) id<GADInterstitialDelegate> delegate;

/// Optional delegate object that receives in-app purchase notifications from this ad. Required for
/// the custom in-app purchase flow, but ignored when using the default in-app purchase flow.
/// Remember to nil this property before deallocating the delegate.
@property(nonatomic, weak) id<GADInAppPurchaseDelegate> inAppPurchaseDelegate;

#pragma mark Making an Ad Request

/// Makes an interstitial ad request. Additional targeting options can be supplied with a request
/// object. Only one interstitial request is allowed at a time.
///
/// This is best to do several seconds before the interstitial is needed to preload its content.
/// Then when transitioning between view controllers show the interstital with
/// presentFromViewController.
- (void)loadRequest:(GADRequest *)request;

#pragma mark Post-Request

/// Returns YES if the interstitial is ready to be displayed. The delegate's
/// interstitialAdDidReceiveAd: will be called after this property switches from NO to YES.
@property(nonatomic, readonly, assign) BOOL isReady;

/// Returns YES if this object has already been presented. Interstitial objects can only be used
/// once even with different requests.
@property(nonatomic, readonly, assign) BOOL hasBeenUsed;

/// Returns the ad network class name that fetched the current ad. Returns nil while the latest ad
/// request is in progress or if the latest ad request failed. For both standard and mediated Google
/// AdMob ads, this method returns @"GADMAdapterGoogleAdMobAds". For ads fetched via mediation
/// custom events, this method returns @"GADMAdapterCustomEvents".
@property(nonatomic, readonly, copy) NSString *adNetworkClassName;

/// Presents the interstitial ad which takes over the entire screen until the user dismisses it.
/// This has no effect unless isReady returns YES and/or the delegate's interstitialDidReceiveAd:
/// has been received.
///
/// Set rootViewController to the current view controller at the time this method is called. If your
/// application does not use view controllers pass in nil and your views will be removed from the
/// window to show the interstitial and restored when done. After the interstitial has been removed,
/// the delegate's interstitialDidDismissScreen: will be called.
- (void)presentFromRootViewController:(UIViewController *)rootViewController;

@end

对于@interface 我得到这个错误:重复的接口定义

对于每个@property,我都会得到这个:属性有一个先前的声明

【问题讨论】:

    标签: objective-c sprite-kit xcode6 admob


    【解决方案1】:

    听起来您的项目中有两个 GoogleMobileAdsSdk 副本。删除其中之一。确保您拥有来自 AdMob 的最新 SDK。然后像这样实现 AdMob 插页式广告。

    #import "ViewController.h"
    // Import AdMob framework in your header file
    // #import <GoogleMobileAds/GoogleMobileAds.h>
    
    // Enter YOUR ad id you receive from AdMob here
    #define INTERSTITIAL_UNIT_ID @"yourAdMobInterstitialID"
    
    @interface ViewController () <GADInterstitialDelegate>
    @end
    
    @implementation ViewController {
        // AdMob
        GADInterstitial *adMobInterstitial;
    }
    
    -(void)viewDidLoad {
        [super viewDidLoad];
    
        // AdMob
        adMobInterstitial = [[GADInterstitial alloc] init];
        adMobInterstitial.adUnitID = INTERSTITIAL_UNIT_ID;
        [adMobInterstitial loadRequest:[GADRequest request]];
    }
    
    // Call this method when you want to show an ad
    // [self showAdMobInterstitial];
    -(void)showAdMobInterstitial {
        // Lets present the ad
        adMobInterstitial.delegate = self;
        [adMobInterstitial presentFromRootViewController:self];
        NSLog(@"adMobInterstitial presentFromRootViewController");
    }
    
    -(void)interstitial:(GADInterstitial *)interstitial didFailToReceiveAdWithError:(GADRequestError *)error {
        // Failed to receive ad from AdMob
        // Lets get another ad for the next time we would like to show one
        adMobInterstitial = nil;
        adMobInterstitial = [[GADInterstitial alloc] init];
        adMobInterstitial.adUnitID = INTERSTITIAL_UNIT_ID;
        [adMobInterstitial loadRequest:[GADRequest request]];
        NSLog(@"didFailToReceiveAdWithError");
        NSLog(@"%@", error);
    }
    
    -(void)interstitialWillDismissScreen:(GADInterstitial *)interstitial {
        NSLog(@"interstitialWillDismissScreen");
    }
    
    -(void)interstitialDidDismissScreen:(GADInterstitial *)interstitial {
        // User received ad and has closed it
        // Lets get another ad for the next time we would like to show one
        adMobInterstitial = nil;
        adMobInterstitial = [[GADInterstitial alloc] init];
        adMobInterstitial.adUnitID = INTERSTITIAL_UNIT_ID;
        [adMobInterstitial loadRequest:[GADRequest request]];
        NSLog(@"interstitialDidDismissScreen");
    }
    

    【讨论】:

    • 到目前为止它似乎工作了谢谢你,但我仍然得到这个日志: 无法呈现插页式广告。还没准备好。
    • 所以我尝试了这个委托方法,它在加载 viewController 后立即触发广告:` -(void)interstitialDidReceiveAd:(GADInterstitial *)ad{ [adMobInterstitial presentFromRootViewController:self]; NSLog(@"adMobInterstitial didReceiveAd"); } ` 但是为什么我不能手动触发它,这行不通??
    • @NeoGER89 你得到了` 不能展示插页式广告。它还没有准备好。 ` 因为您试图过早展示广告。在调用[self showAdMobInterstitial] 之前,您需要给它几秒钟的时间来加载它。在用户做某事后调用它。不是在应用程序首次加载时。 -(void)interstitialDidReceiveAd 并不意味着直接调用。当您的GADInterstitial 成功接收到广告时,它会调用它,以便您可以做一些事情来准备您的应用程序以展示广告。例如,保存游戏状态、暂停声音、禁用计时器等。
    • 我在等待大约 10 秒后按下播放按钮时尝试过。它不起作用,我试图在用户成功登录游戏中心后将其启动。也不行。我让广告显示的唯一方法是在委托方法中。我不知道为什么。我还尝试在代表已经显示广告后显示广告。它不断出现的唯一方式是循环。例如在 interstitialdiddismiss 方法中,我在其中发送一个新请求,然后当我关闭广告时,会出现一个新请求。
    猜你喜欢
    • 2021-12-07
    • 2014-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-26
    • 1970-01-01
    相关资源
    最近更新 更多