【问题标题】:No visible @interface for 'GADUNativeCustomTemplateAd' error“GADUNativeCustomTemplateAd”错误没有可见的@interface
【发布时间】:2017-10-13 01:36:53
【问题描述】:

我得到的错误是:

“GADUNativeCustomTemplateAd”没有可见的@interface 声明选择器“performClickOnAssetWithKeycustomClickHandler:clickHandler:”

谁能帮我解决这个问题?

.m 文件

// Copyright 2014 Google Inc. All Rights Reserved.

#import "GADUNativeCustomTemplateAd.h"

@implementation GADUNativeCustomTemplateAd

 - (instancetype)initWithAd:(GADNativeCustomTemplateAd *)nativeCustomTemplateAd {
  self = [super init];
  if (self) {
    _nativeCustomTemplateAd = nativeCustomTemplateAd;
  }
   return self;
}

- (NSString *)templateID {
  return [self.nativeCustomTemplateAd templateID];
}

- (NSString *)stringForKey:(NSString *)key {
  return [self.nativeCustomTemplateAd stringForKey:key];
}

- (UIImage *)imageForKey:(NSString *)key {
  return [self.nativeCustomTemplateAd imageForKey:key].images;
}

- (void)performClickOnAssetWithKey:(NSString *)key withCustomClickAction:(bool)customClickAction {
  dispatch_block_t clickHandler = nil;
  if (customClickAction) {
    clickHandler = ^{
      [self didReceiveClickForAsset:key];
    };
  }
  [self.nativeCustomTemplateAd performClickOnAssetWithKey:key customClickHandler:clickHandler];
}

- (void)didReceiveClickForAsset:(NSString *)key {
  if (self.didReceiveClickCallback) {
    self.didReceiveClickCallback(self.nativeCustomTemplateClient,
                                 [key cStringUsingEncoding:NSUTF8StringEncoding]);
  }
}

- (void)recordImpression {
  [self.nativeCustomTemplateAd recordImpression];
}

- (NSArray *)availableAssetKeys {
  return [self.nativeCustomTemplateAd availableAssetKeys];
}

@end

.h 文件

// Copyright 2014 Google Inc. All Rights Reserved.

@import Foundation;
@import GoogleMobileAds;

#import "GADUTypes.h"

@interface GADUNativeCustomTemplateAd : NSObject

/// A reference to the Unity native custom template ad client.
@property(nonatomic, assign) GADUTypeNativeCustomTemplateAdClientRef *nativeCustomTemplateClient;

/// A GADNativeCustomTemplateAd which loads native ads.
@property(nonatomic, strong) GADUNativeCustomTemplateAd *nativeCustomTemplateAd;

/// Initializes a GADUNativeCustomTemplateAd.
- (instancetype)initWithAd:(GADNativeCustomTemplateAd *)nativeCustomTemplateAd;

/// The ad clicked callback into Unity.
@property(nonatomic, assign)
GADUNativeCustomTemplateDidReceiveClickCallback didReceiveClickCallback;

/// The custom template ID for the ad.
- (NSString *)templateID;

/// Returns the string corresponding to the specified key.
- (NSString *)stringForKey:(NSString *)key;

/// Returns the native ad image corresponding to the specified key.
- (UIImage *)imageForKey:(NSString *)key;

/// Call when the user clicks on the ad.
- (void)performClickOnAssetWithKey:(NSString *)key withCustomClickAction:(bool)clickAction;

/// Call when the ad is displayed on screen to the user.
- (void)recordImpression;

/// An array of available asset keys.
- (NSArray *)availableAssetKeys;

@end

【问题讨论】:

    标签: ios objective-c iphone xcode nsstring


    【解决方案1】:

    在您的 header 文件中,尝试更改 nativeCustomTemplateAd 属性声明:

    @property(nonatomic, strong) GADUNativeCustomTemplateAd *nativeCustomTemplateAd;
    

    到这里:

    @property(nonatomic, strong) GADNativeCustomTemplateAd *nativeCustomTemplateAd;
    

    ...您可能只是在类名中有一个愚蠢的拼写错误。

    【讨论】:

    • 很好,所以我认为我们解决了您原来的问题 :) 这个 googlesignin 错误 可能是一个全新的问题...
    • 遵循 SO 指南,您最好打开一个 new question 来解决这个其他问题(并链接回这个问题,作为参考)。
    • 所以一切都很好,但现在我得到链接器命令未能退出代码 1(使用 -v 查看调用)
    • @ompatel 如果我的回答解决了您最初的问题,请务必在有机会时接受/投票...谢谢兄弟:)
    【解决方案2】:

    您需要在 .h 文件中定义 performClickOnAssetWithKey:customClickHandler: int。并在这个文件中实现这个方法。

    【讨论】:

    • 它被定义为 - (void)performClickOnAssetWithKey:(NSString *)key withCustomClickAction:(bool)clickAction;在h文件中
    • 你的回答很详细,我只是展示了一个方法签名。但是我发现他可能想写一个递归方法,如果我猜对了,只需修复错误行,执行ClickOnAssetWithKey:withCustomClickAction:但他想要其他单元格,需要像你说的那样定义一个新方法,但没有“with” head of “ customClickAction:(bool)clickAction; "
    【解决方案3】:

    您的 GADUNativeCustomTemplateAd.h 文件和 GADUNativeCustomTemplateAd.m 文件中都需要一个 @interface/@end 部分。

    在 m 文件中,它应该在 #import 之后和 @implementation 之前,看起来像

    @interface GADUNativeCustomTemplateAd()
    // private properties of your GADUNativeCustomTemplateAd class
    @end
    

    在h文件中应该是这样的:

    @interface GADUNativeCustomTemplateAd : UIViewController
    {  
    }
    // public properties of your GADUNativeCustomTemplateAd class
    @end
    

    如果 GADUNativeCustomTemplateAd 不是从 UIViewController 派生的,您应该使用它派生的任何类。

    【讨论】:

    • 好的,所以我这样做了,但是一旦我输入“@interface”,它就会告诉我输入“@end”,中间没有任何内容,错误仍然存​​在,所以你能帮助我更多吗详细。
    • 向我们展示您的 GADUNativeCustomTemplateAd.h 文件的内容
    猜你喜欢
    • 2012-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-09
    • 2021-11-07
    相关资源
    最近更新 更多