iOS:Google Analytics 和 AdMob 的 CocoaPods 问题

iOS: CocoaPods issue with Google Analytics and AdMob

假设:

当我启动应用程序时收到警告:

You have enabled the AdMob service in Developer Console, but it appears as though your Podfile is missing the line: 'pod "Google/AdMob" or you may need to run pod update in your project directory.

然后应用程序崩溃并出现错误:

assertion failed: Error configuring Google services: Optional(Error Domain=com.google.greenhouse Code=-106 "Missing expected subspecs." UserInfo={NSLocalizedFailureReason=Some subspecs are not pod installed. See log for details., NSLocalizedDescription=Missing expected subspecs.}): file /myapp/AppDelegate.swift

由断言行抛出,此代码 Google Analytics 文档说要添加到 AppDelegate.swift 文件中:

// Configure tracker from GoogleService-Info.plist.
var configureError:NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError)")



我试着替换

pod 'Google-Mobile-Ads-SDK', '~> 7.0'pod 'Google/AdMob'

应用程序不再崩溃,但我收到警告:

You are currently using version 7.6.0 of the SDK. Please consider updating your SDK to the most recent SDK version to get the latest features and bug fixes


这是我的完整 Podfile:

source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '8.0'
use_frameworks!  # needed when using Swift


target 'myProject' do

    pod 'Google/Analytics'
    pod 'GoogleIDFASupport'
    pod 'Google-Mobile-Ads-SDK', '~> 7.0'

    pod 'Fabric'
    pod 'Crashlytics'

    pod 'SQLite.swift', '~> 0.9.2'    

end

我遇到了同样的问题

改变

pod 'Google-Mobile-Ads-SDK', '~> 7.0'

pod 'Google/AdMob'

唯一的问题是 pod 'Google/AdMob' 比 (7.6) 晚了一个版本

我决定使用 Google/AdMob 的 pod 行,由 GoogleService-Info.plist 配置文件支持,因为它似乎是管理多个 Google 服务的最一致的方式。

唯一的问题是它目前的更新周期较慢:那里的 AdMob pod 仍然是 7.6 版本,而不是最新的 7.7。但是我还是更喜欢那样。无论如何它应该经常更新。

您是否尝试过编辑 GoogleService-Info.plist 并将 "IS_ADS_ENABLED" 更改为 "NO"?如果您使用 "Google-Mobile-Ads-SDK" 而不是 "Google/AdMob",那么您的广告应该仍然有效。 "GoogleService-Info.plist" 不是 AdMob 的必要条件 (https://developers.google.com/admob/ios/quick-start#prerequisites)。

使用 GoogleService-Info.plist 文件很容易维护。

只有 enable/disable 个您想要的服务:

如果您选择要使用其中的一些,则需要在 Podfile 中指定它们。例如。

pod 'Google/CloudMessaging'

Google 个 SDK 的完整列表可用 here

另一种方法是指定您要使用 Firebase。只需修改您的 Podfile:

pod 'Firebase/Core'