iOS:安装 Google 移动广告 SDK 的指令有误?

iOS: Wrong instruction in installing Google Mobile Ads SDK?

我正在按照本教程在我的页面上放置 Google 广告:https://firebase.google.com/docs/admob/ios/quick-start

在这一步:

GADMobileAds.configureWithApplicationID("ca-app-pub-8123415297019784~8909888406");

并且发生错误:

AppDelegate.swift:58:9: Type 'GADMobileAds' has no member 'configureWithApplicationID'

查看后发现没有会员configureWithApplicationID

这条指令有什么问题? 为什么我必须在此版本中安装 Firebase/Core?

这是 GADMobileAds 中的方法,没有像 Objective C 版本那样的 configureWithApplicationID。多蠢http://i.imgur.com/Od0vkPg.png

我在 GADMobileAds.h 中看到了它。检查您是否拥有最新版本。

//
//  GADMobileAds.h
//  Google Mobile Ads SDK
//
//  Copyright 2015 Google Inc. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface GADMobileAds : NSObject

/// Returns the shared GADMobileAds instance.
+ (GADMobileAds *)sharedInstance;

/// Configures the SDK using the settings associated with the given application ID.
+ (void)configureWithApplicationID:(NSString *)applicationID;

从指令中删除 cocoapods 行并替换为此行:

pod 'Google-Mobile-Ads-SDK'

它将安装 google sdk 7.9.0 版本,您将看到 configureWithApplicationID 方法。这是 Google 对 Swift 的错误。

尝试将 Podfile 更新为以下内容:

#pod 'Firebase/AdMob' 
pod 'Google-Mobile-Ads-SDK'

Xcode7.3,iOS9.3.3

按照上面的说明进行操作,但想扩展,希望能节省一些人的时间。 如果您已经安装了 'Google-Mobile-Ads-SDK' pod,请检查版本以确保它是 7.9.0+。否则,您将不断安装旧版本。

要更新版本,请按照 Cocoapods 网站上的说明进行操作 https://cocoapods.org/pods/Google-Mobile-Ads-SDK 单击 "Installation Guide"(右下角):

“~> 7.9”位将强制更新。

我有的东西不起作用:

需要的内容:

再次注意版本是 7.9.1

Podfile 如下所示:

# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'

target 'AppName' do
  # Uncomment this line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # Pods for AppName

  pod 'Firebase'
  pod 'Google-Mobile-Ads-SDK', '~> 7.9'

  target 'AppNameTests' do
    inherit! :search_paths
    # Pods for testing
  end
end

现在您将能够使用 Google 规定的方法配置 GADMobileAds:

[GADMobileAds configureWithApplicationID:@""];

或 Swift 等价物:

GADMobileAds.configureWithApplicationID("");

希望这对您有所帮助!干杯。

我最近尝试将我的广告连播更新到 pod 'Google-Mobile-Ads-SDK', '~> 7.9',但它对我不起作用。因为我的文件中已经有 Google-Mobile-Ads-SDK 的版本,所以我只需要 运行 pod update。问题是 Google 已将 SDK 更新到 7.9 以上,更新而不是命名特定版本可确保您获得最新版本。

Google文档中的说明没问题。我 运行 遇到与 CocoaPods 安装旧版本相同的问题。使用 Cocoa Pods 更新命令,它获取最新版本的 Admob,错误消失。

将 SDK 导入 iOS 项目的最简单方法是使用 CocoaPods。打开项目的 Podfile 并将此行添加到应用的目标中:

pod 'Google-Mobile-Ads-SDK'

然后从命令行运行:

pod install --repo-update

如果您是 CocoaPods 的新手,请参阅他们的 official documentation 了解有关如何创建和使用 Podfile 的信息。