0

我正在为 phonegap 使用这个 AdMob 插件,它运行良好吗?如果你需要,你可以在这里阅读我是如何做到的。我的问题是如何使用此插件为我的 iOS 应用创建插页式广告(占据整个屏幕)?

谢谢您的帮助!

4

1 回答 1

0

所以看起来你必须编写自己的代码才能让插页式广告发挥作用。看看那个插件,它看起来只适用于横幅。不知道您对 Objective C 开发有多熟悉,但我可以尝试为您提供实现的高级概述。

如果需要,您可以创建一个新插件或将其添加到现有插件中。只是把它从我的头顶扔掉,所以怀疑它是否会在没有编译错误的情况下工作,等等:

- (void) createInterstitial:(NSMutableArray *)arguments withDict:(NSMutableDictionary *)options
{
    NSLog(@"Create Interstitial executed");
    // Make sure you create an adInterstitial property
    if(self.adInterstitial)
        return;

    if([options objectForKey:@"siteId"])
    {
        NSLog(@"Setting site Id");
        self.siteId=[[options objectForKey:@"siteId"] description];
    }

    // Note that the GADBannerView checks its frame size to determine what size
    // creative to request. 
    //Initialize the banner off the screen so that it animates up when displaying
    self.adInterstitial = [[[GADInterstitial alloc] init] autorelease];
    // Note: Edit SampleConstants.h to provide a definition for kSampleAdUnitID
    // before compiling.
    self.adInterstitial.adUnitID = self.siteId;
    self.adInterstitial.delegate = self;

}

- (void) loadInterstitial:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{    
    NSLog(@"Load interstitial executed");
    if(!self.adInterstitial)
        [self createInterstitial:arguments withDict:options];

    GADRequest *request = [self createRequest];
    [self setLocation:&request withDict:options];
    [self.adInterstitial loadRequest:request];
}

- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial {
    [interstitial presentFromRootViewController:self];
    [self.webView stringByEvaluatingJavaScriptFromString:@"window.plugins.AdMob.adViewDidReceiveAdCallback();"];

}

- (void)interstitial:(GADInterstitial *)interstitial
    didFailToReceiveAdWithError:(GADRequestError *)error {
    NSLog(@"Failed to receive ad with error: %@", [error localizedFailureReason]);
    NSString* jsString = [NSString stringWithFormat:@"window.plugins.AdMob.didFailToReceiveAdWithErrorCallback(%@);", 
                          [error localizedFailureReason]];
    [self.webView stringByEvaluatingJavaScriptFromString:jsString];
}
于 2012-08-13T14:43:04.853 回答