iOS:Google Analytics和AdMob的CocoaPods问题

Dan*_*e B 7 google-analytics admob ios cocoapods swift

假设:

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

您已在开发者控制台中启用了AdMob服务,但看起来好像您的Podfile缺少"pod"Google/AdMob"或者您可能需要pod update在项目目录中运行.

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

断言失败:配置Google服务时出错:可选(错误域= com.google.greenhouse代码= -106"缺少预期的子规格."UserInfo = {NSLocalizedFailureReason =某些子规格未安装pod.有关详细信息,请参阅日志.,NSLocalizedDescription =缺少预期subspecs.}):file /myapp/AppDelegate.swift

这个代码由断言行引发,谷歌分析文档说要添加到AppDelegate.swift文件中:

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



我试着替换

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

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

您目前使用的是SDK 7.6.0版.请考虑将SDK更新为最新的SDK版本,以获取最新功能和错误修复


这是我的完整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
Run Code Online (Sandbox Code Playgroud)

sta*_*hop 18

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

只需启用/禁用所需的服务:

在此输入图像描述

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

pod 'Google/CloudMessaging'
Run Code Online (Sandbox Code Playgroud)

此处提供完整的Google SDK列表.

另一种方法是指定您要使用Firebase.只需调制你的Podfile:

pod 'Firebase/Core'
Run Code Online (Sandbox Code Playgroud)


Dan*_*e B 1

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

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