ios - 使用 GoogleService-Info.plist 配置适用于 iOS 应用程序的 Google 分析时出错

标签 ios objective-c xcode google-analytics spritebuilder

我关注了这个Google developer guide使用 Cocoa Pods 将 Google Analytics 添加到 iOS 应用程序。我添加了 GoogleService-Info.plist 并将初始化代码放在 didFinishLaunchingWithOptions 中。该应用程序构建良好,但随后在尝试初始化 GA 时崩溃。特别是这些代码行:

NSError *configureError;
[[GGLContext sharedInstance] configureWithError:&configureError];
NSAssert(!configureError, @"Error configuring Google services: %@", configureError);

断言语句失败,控制台输出为:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
reason: 'Error configuring Google services: 
Error Domain=com.google.greenhouse Code=-200 "Unable to configure GGL."
{NSLocalizedFailureReason=Unable to parse supplied GoogleService-Info.plist. See log for details., 
NSLocalizedRecoverySuggestion=Check formatting and location of GoogleService-Info.plist., 
NSLocalizedDescription=Unable to configure GGL.}'

我可以看出这是由于 GoogleService-Info.plist 文件造成的,经过一些调查我发现即使我删除了 GoogleService-Info.plist 我也得到了错误,这让我相信我没有正确地将文件添加到项目中。

这是我在添加文件时检查的内容的屏幕截图:

enter image description here

所以我确保它被添加到所有目标并且文件位于项目的根目录中,与 xcodeprojxcworkspace 文件一起,作为按照 Google 开发人员指南中的说明。

我还应该提到这是一个 SpriteBuilder 项目,但我认为这与此无关。这也是我添加的第一个 Cocoa Pod,但随着项目的构建,一切似乎都很好,并且可以找到它需要的所有 Google header 。

最佳答案

我也被这段奇怪的代码困住了。但你不需要它!只需删除 configureWithError 和所有这些东西。

您只需要:

[[GAI sharedInstance] trackerWithTrackingId:@"UA-11111111-2"];
[GAI sharedInstance].trackUncaughtExceptions = YES;

didFinishLaunchingWithOptions 里面的某个地方。 (它来自以前的 GA 版本,对吗?)所以,就是这样!然后,在您的应用中执行任何您想做的事情:

id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker set:kGAIScreenName value:@"start screen"];
[tracker send:[[GAIDictionaryBuilder createScreenView] build]];

我的 Podfile 看起来像这样:

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

pod 'Google/Analytics', '~> 1.0.0'

有效!

关于ios - 使用 GoogleService-Info.plist 配置适用于 iOS 应用程序的 Google 分析时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31333828/

相关文章:

ios - 如何在 Swift 中放大或缩小 MKMapView?

ios - 如何设置UILabel的文本参数

ios - 应用程序快捷方式打开 TableView 行

ios - NSURLConnection 完成错误 - 1001

ios - Xcode不显示任何连接的设备

ios - 我们可以从我们的 ios 应用程序启动我们的应用程序设置页面吗?

iOS 委托(delegate)取消调用失败

ios - 未使用的 xib 出现在应用程序中

关于文件名的 Xcode 问题

iphone - Xcode 4 无法将 iPhone 识别为配置设备