- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 ios 上实现 Admob Interstitial 广告。
这是我目前的情况,这是我第一次接触 objective-c,所以请多关照。
// Simple Admob Interstitial support for Monkey - IOS
// admobInterstitial.ios.h
#import "GADInterstitial.h"
class AdmobInterstitial {
// the kind of "singleton"
static AdmobInterstitial *_admob;
// the ad
GADInterstitial *_interstitialAd;
// ad Unit ID
NSString *adUnitId;
public:
AdmobInterstitial();
// creates an instance of the object and start the thread
static AdmobInterstitial *GetAdmobInterstitial(String adUnitId);
// displays the ad to the user if it is ready
void ShowAd();
};
// admobInterstitial.ios.cpp
AdmobInterstitial *AdmobInterstitial::_admob;
AdmobInterstitial::AdmobInterstitial():_interstitialAd(0) {
}
AdmobInterstitial *AdmobInterstitial::GetAdmobInterstitial(String adUnitId) {
if( !_admob ) _admob=new AdmobInterstitial();
_admob->adUnitId = adUnitId.ToNSString();
return _admob;
}
void AdmobInterstitial::ShowAd() {
// create ad (should this go here or earlier?)
_interstitialAd = [[GADInterstitial alloc] init];
if (_interstitialAd) {
_interstitialAd.adUnitID = adUnitId;
[_interstitialAd loadRequest:[GADRequest request]];
if (_interstitialAd.isReady) {
BBMonkeyAppDelegate *appDelegate=(BBMonkeyAppDelegate*)[[UIApplication sharedApplication] delegate];
UIViewController *rootViewController = appDelegate->viewController;
[_interstitialAd presentFromRootViewController:rootViewController];
}
}
}
我在我的游戏中调用 ShowAd() 在玩家死亡并点击重启按钮后。目前,_interstitialAd.isReady 不会恢复为 true。
这是我用来入门的文档 https://developers.google.com/mobile-ads-sdk/docs/admob/advanced#ios
它表示“您可以随时调用 loadRequest:但是,您必须等待 GADInterstitialDelegate 的 interstitialDidReceiveAd:在显示广告素材之前被调用。”
我想这就是我遇到的问题。我想我是在 interstitialDidReceiveAd 之前调用 loadRequest。但是,该文档没有显示我将如何等待调用此方法的示例。
有人可以帮忙吗?
编辑:现在工作并在我第一次调用 ShowAd() 时显示广告,但是在第一次调用此函数后任何时候都不会显示广告
// Simple Admob Interstitial support for Monkey - IOS
// admobInterstitial.ios.h
#import "GADInterstitial.h"
class AdmobInterstitial {
// the kind of "singleton"
static AdmobInterstitial *_admob;
// the ad
GADInterstitial *_interstitialAd;
// ad Unit ID
NSString *adUnitId;
void loadAd();
public:
AdmobInterstitial();
// creates an instance of the object and start the thread
static AdmobInterstitial *GetAdmobInterstitial(String adUnitId);
// displays the ad to the user if it is ready
void ShowAd();
};
// admobInterstitial.ios.cpp
AdmobInterstitial *AdmobInterstitial::_admob;
AdmobInterstitial::AdmobInterstitial():_interstitialAd(0) {
}
AdmobInterstitial *AdmobInterstitial::GetAdmobInterstitial(String adUnitId) {
if( !_admob ) _admob=new AdmobInterstitial();
_admob->adUnitId = adUnitId.ToNSString();
_admob->loadAd();
return _admob;
}
void AdmobInterstitial::loadAd() {
// testing
_interstitialAd = [[GADInterstitial alloc] init];
if (_interstitialAd) {
_interstitialAd.adUnitID = adUnitId;
[_interstitialAd loadRequest:[GADRequest request]];
}
// end testing
}
void AdmobInterstitial::ShowAd() {
// create ad (should this go here or earlier?)
//_interstitialAd = [[GADInterstitial alloc] init];
if (_interstitialAd) {
//_interstitialAd.adUnitID = adUnitId;
//[_interstitialAd loadRequest:[GADRequest request]];
if (_interstitialAd.isReady) {
BBMonkeyAppDelegate *appDelegate=(BBMonkeyAppDelegate*)[[UIApplication sharedApplication] delegate];
UIViewController *rootViewController = appDelegate->viewController;
[_interstitialAd presentFromRootViewController:rootViewController];
}
}
}
最佳答案
好的。首先 isAdReady==false 会在没有广告可展示时发生。即这是自然条件。您可以使用调解来缓解它。
但在您的情况下,很可能没有广告可供展示,因为在提出该问题之前没有足够的时间发送广告请求并收到回复。
您需要做的是尽早调用loadAd。即当你游戏第一次开始时。然后在游戏的自然中断点(玩家死亡后)检查 isAdReady 是否为真,如果是则显示广告。
当您显示广告或游戏再次启动时,再次调用 loadAd 以便您下次要显示广告时再次准备好广告。
关于ios - Admob Interstitial isReady 为 False,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22723894/
class test { public static void main(String[] args){ Object o1 = new Object(); O
我以为我理解了 Python 中的这两个单例值,直到我看到有人在代码中使用 return l1 or l2,其中 l1 和 l2 都是链表对象,并且(s)他想如果不为 None 则返回 l1,否则返回
这个问题在这里已经有了答案: Why does the expression 0 >> (True == False) is False True >>> True == (False is Fals
为什么在 Python 中它是这样评估的: >>> False is False is False True 但是当用括号尝试时表现如预期: >>> (False is False) is False
我有一个名为“apple”的表,我编写了以下查询: select name, count(name), case when istasty is null then fal
python boolean 逻辑中的运算符优先级 print(False==True or False) #answer is True print(False==(False or True))#
请不要看条件,因为它们在这里是为了便于理解行为 为什么 result 等于 true ? boolean result = false && (false)?false:true; 我知道我们可以通过
乍一看,这篇文章可能看起来像是重复的,但事实并非如此。相信我,我已经查看了所有 Stack Overflow,但都无济于事。 无论如何,我从 Html.CheckBoxFor 得到了一些奇怪的行为。
这个问题在这里已经有了答案: python operator precedence of in and comparison (4 个答案) 关闭 6 年前。 我的一位前辈演示了它,我想知道这是否是
我最近参加了 Java 的入门测试,这个问题让我很困惑。完整的问题是: boolean b1 = true; boolean b2 = false; if (b2 != b1 != b2) S
为什么 {} == false 评估为 false 而 [] == false 评估为 true在 javascript 中? 最佳答案 这是根据 Abstract Equality Comparis
这个问题在这里已经有了答案: Why does (1 in [1,0] == True) evaluate to False? (1 个回答) 关闭7年前。 为什么使用括号时这些语句按预期工作: >>
我试过搜索这个,但我真的不知道如何表达它以查看是否有其他人发布了答案。 但是,我正在制作一个国际象棋游戏和一个人工智能来配合它,这是非常困难的,我的问题是当我检查两个棋子是否在同一个团队时我必须做 (
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
为什么 为 false || null 返回与 null || 不同的结果错误? 我可以安全地依赖 return myVar || false 如果 myVar 为 null 或 false,则返回
我正在尝试遵循 NHibernate 教程,“你的第一个基于 NHibernate 的应用程序:修订 #4”在 NHibernate Forge。 但线路:new SchemaExport(cfg).
这个问题在这里已经有了答案: Empty list boolean value (3 个答案) 关闭 4 年前。 我是 Python 的新手,不理解以下行为: 为什么要声明 [] == False
以下函数循环访问对象的值。如果值为空this.hasInvalidValue设置为true ,如果不为空 this.hasInvalidValue设置为false : user: { email:
所以我正在玩 java.lang.reflect 东西并尝试制作类似 this 的东西。这是我的问题(可能是一个错误): 将字段设置为 true 的方法的代码: private static void
当我在编程时,我的 if 语句出现了意想不到的结果。 这个代码警报怎么会是真的?我在 W3S 没有找到任何可以帮助我的东西,我真的很想知道为什么这些警报是“正确的” window.alert(fals
我是一名优秀的程序员,十分优秀!