1

GADInterstitialDelegate 和 IMInterstitialDelegate 具有相同的函数名称:interstitialDidReceiveAd

//inmob
- (void)interstitialDidReceiveAd:(IMInterstitial *)ad
                        //callback:(id<IMInterstitialDelegate>)callback
{
    [ad presentInterstitialAnimated:YES];
      NSLog(@"!!! inmob interstitialDidReceiveAd ok ");
}

// Sent when an interstitial ad request failed
- (void)interstitial:(IMInterstitial *)ad didFailToReceiveAdWithError:(IMError *)error
            //callback:(id<IMInterstitialDelegate>)callback
{
        NSLog(@"!!! inmob didFailToReceiveAdWithError ");
   // NSString *errorMessage = [NSString stringWithFormat:@"Loading ad (%@) failed. Error code: %d, message: //%@", [self.detailItem objectForKey:@"title"], [error code], [error localizedDescription]];
    //NSLog(@"%@", errorMessage);
}

//admob
- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitialAdmob
{
    NSLog(@"!!! admob interstitialDidReceiveAd ok");
}

- (void)interstitial:(GADInterstitial *)interstitial
            //callback:(id<GADInterstitialDelegate>)callback
didFailToReceiveAdWithError:(GADRequestError *)error
{
    NSLog(@"!!!!!!! admob interstitial error!");
}

构建错误:方法“interstitialDidReceiveAd:”的重复声明

4

1 回答 1

6

Objective-C 不允许多个具有相同名称但接受不同类型的方法。幸运的是,它也是弱类型的。所以你应该能够逃脱:

- (void)interstitialDidReceiveAd:(id)interstitial
{
    if([interstitial isKindOfClass:[GADInterstitial class]])
        [self admobInterstitialDidReceiveAd:interstitial];
    else
        [self inmobiInterstitialDidReceiveAd:interstitial];
}

或者任何基于接收id并在它到达时检查其类型的更彻底的测试。

于 2014-08-28T15:31:28.370 回答