即使导入 AdMob 框架也找不到
删除框架并再次导入。确保您选中“如果需要,复制项目”。另外,请检查项目设置和构建阶段下的库搜索路径,以查看是否包含该框架。
我导入了AdMob所需的所有框架
这是没有必要的。一旦您包含,AdMob 框架将导入它需要的框架import GoogleMobileAds
.
而且我没有碰故事板。我必须在故事板中创建一些东西吗?
No
在将应用程序提交到 App Store 之前,我必须删除测试设备行并放入我的真实 AdUnitID?
是的。现在尝试使用您的真实 AdUnitID,看看您的测试 ID 是否导致了问题。
也许代码是正确的,但如果应用程序未发布,AdMob 将无法加载,或者我可能需要等待一天才能让我的 AdMob id 开始工作
不需要。无需发布应用程序即可接收实时广告。
在哪里可以找到最近的 AdMob ID 进行测试?所以我测试了应用程序,如果有效,我更改 id 并提交
无处。泄露您的 AdUnitID 并不明智。
关于 AdMob 指南的另一个问题是,在其他应用程序中,我可以在一个视图中使用 iAd,在另一个视图中使用 AdMob 吗?我可以因此被禁止吗?仅屏幕下方的横幅广告
您可以根据需要在应用程序中使用任意数量的广告网络。没有任何内容表明您不被允许这样做。
听起来你走在正确的轨道上。您应该设置并包含插页式广告的委托方法,以查看是否收到任何错误消息。您需要允许任意负载.plist
也。查看AdMob 的 iOS 9 注意事项 https://developers.google.com/admob/ios/ios9.
你打电话吗createNloadAd()
在您尝试在您的广告中呈现插页式广告之前viewDidLoad
?下载广告需要时间。
确保 AdMob 提供的 AdUnitID 与您正在使用的 AdUnitID 相同。
另外,将演示文稿从viewDidLoad
to viewDidAppear
.
这是在我们的页面中创建插页式广告的示例AppDelegate.swift
然后在我们的页面中呈现插页式广告ViewController.swift
:
AppDelegate.swift
import UIKit
import GoogleMobileAds // Import AdMob
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GADInterstitialDelegate { // Include delegate
var window: UIWindow?
var myInterstitial : GADInterstitial?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// App launched
// Load interstitial
myInterstitial = createAndLoadInterstitial()
return true
}
func createAndLoadInterstitial()->GADInterstitial {
let interstitial = GADInterstitial(adUnitID: "Your Ad Unit ID")
interstitial.delegate = self
interstitial?.loadRequest(GADRequest())
return interstitial
}
func interstitialDidReceiveAd(ad: GADInterstitial!) {
print("interstitialDidReceiveAd")
}
func interstitial(ad: GADInterstitial!, didFailToReceiveAdWithError error: GADRequestError!) {
print(error.localizedDescription)
}
func interstitialDidDismissScreen(ad: GADInterstitial!) {
print("interstitialDidDismissScreen")
myInterstitial = createAndLoadInterstitial()
}
ViewController.swift(这将是您的游戏结束视图控制器)
import UIKit
class ViewController: UIViewController {
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate // Create reference to our app delegate
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(animated: Bool) {
appDelegate.myInterstitial?.presentFromRootViewController(self)
}