【发布时间】:2012-08-11 09:51:28
【问题描述】:
我正在使用this AdMob plugin for phonegap,它工作正常吗?你可以read here how I did it if you need。我的问题是如何使用此插件为我的 iOS 应用创建插页式广告(占据整个屏幕)?
感谢您的帮助!
【问题讨论】:
标签: cordova admob ads phonegap-plugins interstitial
我正在使用this AdMob plugin for phonegap,它工作正常吗?你可以read here how I did it if you need。我的问题是如何使用此插件为我的 iOS 应用创建插页式广告(占据整个屏幕)?
感谢您的帮助!
【问题讨论】:
标签: cordova admob ads phonegap-plugins interstitial
看来您必须编写自己的代码才能让插页式广告发挥作用。看看那个插件,它看起来只适用于横幅。不知道您对 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];
}
【讨论】: