ios - 如何在委托(delegate)中加载插页式广告并在另一个 View Controller 中显示?
<p><p>我试图在应用程序午餐后立即请求 Admob 插页式广告,因此我尝试在 appDelegate.m 中实现,但是当我稍后尝试在另一个 ViewController 中显示它时,我收到一个错误,即插页式标识符在此 ViewController 中找不到。</p>
<p>这是我正在使用的代码</p>
<p>在 AppDelegate.m 中</p>
<pre><code> @property(nonatomic, strong) GADInterstitial *interstitial;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Interstitial Ad
self.interstitial = [ initWithAdUnitID:@"ca-app-pub-1232434xxxxxxx"];
GADRequest *request2 = ;
request2.testDevices = @;
;
</code></pre>
<p>然后在任何 viewcontroller.m 中</p>
<pre><code>- (void)loadInterstitialAd {
if () {
;
;
timer= nil;
}
}
</code></pre>
<p>我似乎无法将标识符或函数从委托(delegate)传递给任何 ViewController 。</p>
<p>非常感谢您的帮助。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>解决方案很简单,对我有用。</p>
<p>将 AppDelegate 设为 GADInterstitial 的代表。在 AppDelegateheader 中添加 GADInterstitialDelegate。</p>
<p>在 AppDelegate 类中添加这些函数。 AppDelegate 中还有 gViewController 变量。每当您将新的 viewControler 更改为此时,分配它。从 AppDelegate 类调用 showAdmobFullScreenAds。</p>
<pre><code>-(void)showAdmobFullScreenAds
{
GADInterstitial * interstitial_ = [ initWithAdUnitID:MY_ADMOB_FULLSCREEN_UNIT_ID];
interstitial_.delegate = self;
];
}
- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial
{
;
}
- (void)interstitial:(GADInterstitial *)interstitial didFailToReceiveAdWithError:(GADRequestError *)error
{
printf("Error\n");
}
</code></pre>
<p>从其他 ViewControllers 中,将下面的函数放在所有其他 viewController 中</p>
<pre><code> override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
let App = UIApplication.sharedApplication().delegate as! AppDelegate
App.gViewController = self;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何在委托(delegate)中加载插页式广告并在另一个 ViewController 中显示?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/35098785/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/35098785/
</a>
</p>
页:
[1]