使用GoogleService-Info.plist为iOS应用配置Google分析时出错

Cho*_*c13 5 xcode google-analytics objective-c ios spritebuilder

我按照Google开发人员指南,使用Cocoa Pod将Google分析添加到iOS应用中.我添加了GoogleService-Info.plist并将初始化代码放入didFinishLaunchingWithOptions.该应用程序构建正常,但然后在尝试初始化GA时崩溃.特别是这些代码行:

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

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

*** 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.}'
Run Code Online (Sandbox Code Playgroud)

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

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

在此输入图像描述

所以我确信,它被添加到所有目标和该文件是在项目的根目录下,一起xcodeproj和xcworkspace文件,按照在谷歌开发者指南中的说明.

我还要提一下,这是一个SpriteBuilder项目,但我认为这与此无关.这也是我添加的第一个Cocoa Pod,但随着项目的构建,它可以找到所需的所有Google标题.

Dmi*_*aev 6

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

所有你需要的是:

[[GAI sharedInstance] trackerWithTrackingId:@"UA-11111111-2"];
[GAI sharedInstance].trackUncaughtExceptions = YES;
Run Code Online (Sandbox Code Playgroud)

在某处内有didFinishLaunchingWithOptions.(它来自之前的GA版本,对吗?)所以,就是这样!然后,在您的应用中执行任何操作:

id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker set:kGAIScreenName value:@"start screen"];
[tracker send:[[GAIDictionaryBuilder createScreenView] build]];
Run Code Online (Sandbox Code Playgroud)

我的Podfile看起来像这样:

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

pod 'Google/Analytics', '~> 1.0.0'
Run Code Online (Sandbox Code Playgroud)

有用!