【问题标题】:Firebase/Admob installation guide with pods on Cocoapods site vs Firebase installation guide on googleFirebase/Admob 安装指南与 Cocoapods 网站上的 pod 与 Google 上的 Firebase 安装指南
【发布时间】:2017-09-01 03:30:50
【问题描述】:

我正在尝试使用 Cocoapods 为 ios 应用程序集成 firebase/admob 广告。 在 Cocoapods 网站上有一个指南,例如先下载 Cocoapods,然后在应用程序中创建一个 pod 文件并使用 pods 添加代码。在 Google 网站上也有关于如何使用 pod 安装 firebase ads sdk 的说明,但似乎我还需要在实际应用程序中插入诸如 gad 等编码。我是新手,所以我有点困惑 - Cocoapods 编码是否足够,或者我是否还需要在应用程序中添加编码,以初始化广告或为特定广告(如横幅/插页式广告等)创建按钮?

【问题讨论】:

标签: ios swift firebase admob


【解决方案1】:

您还必须在应用程序中添加一些编码,以便在应用程序委托中导入 Googlemobileads 并在 func didFinishLaunchingWithOptions 中对其进行配置:

GADMobileAds.configure(withApplicationID: "Your application id")

然后在您的第一个控制器或您要显示添加的控制器中添加以下代码:

var bannerView: GADBannerView!    
bannerView = GADBannerView(adSize: kGADAdSizeSmartBannerPortrait)
bannerView.frame.origin.y = self.view.frame.size.height - bannerView.frame.size.height
self.view.addSubview(bannerView)
bannerView.adUnitID = "Your ad unit id"
bannerView.rootViewController = self
bannerView.load(GADRequest())

【讨论】:

  • 谢谢。我的问题是,当我尝试添加编码时,admob 网站的说明也是如此,除非我在开​​头使用“//”开始编码,否则我无法完成任何工作。否则我会收到一条消息“firebase”(如果我使用 import firebase)或找不到其他文件(带有红色感叹号)(?)
  • 您必须安装 pod 'Google-Mobile-Ads-SDK' 然后导入 Googlemobileads 而不是 firebase。
【解决方案2】:

另外,我认为代码是用 C 语言编写的,这就是我遇到问题的原因,而不是 Swift。我已经设法完成了几乎所有事情 - 当我使用 self.bannerView 和 GADBannerView 以及之前未声明的消息时遇到问题。我尝试遵循 Objective C,因为这就是代码的样子,但似乎无法解决这个问题。

【讨论】:

    猜你喜欢
    • 2014-05-17
    • 1970-01-01
    • 2019-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-22
    相关资源
    最近更新 更多