xcode 使用 GoogleService-Info.plist 为 iOS 应用配置 Google 分析时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31333828/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error configuring Google analytics for iOS app with GoogleService-Info.plist
提问by Choc13
I followed this Google developer guideto add Google analytics to an iOS app using Cocoa Pods. I added the GoogleService-Info.plist
and put the initialisation code in didFinishLaunchingWithOptions
. The app builds fine, but then crashes at the point it tries to initialise GA. Specifically these lines of code:
我按照此Google 开发人员指南使用 Cocoa Pods 将 Google 分析添加到 iOS 应用程序。我添加了GoogleService-Info.plist
并将初始化代码放在didFinishLaunchingWithOptions
. 该应用程序构建良好,但在尝试初始化 GA 时崩溃。特别是这几行代码:
NSError *configureError;
[[GGLContext sharedInstance] configureWithError:&configureError];
NSAssert(!configureError, @"Error configuring Google services: %@", configureError);
The assert statement is failing and the output in the console is:
assert 语句失败,控制台中的输出是:
*** 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.}'
I can see this is due to the GoogleService-Info.plist
file and after some investigation I found that even if I delete GoogleService-Info.plist
I get the error, which leads me to believe that I had not added the file to the project correctly.
我可以看到这是由于GoogleService-Info.plist
文件造成的,经过一些调查,我发现即使我删除GoogleService-Info.plist
我也会收到错误,这让我相信我没有正确地将文件添加到项目中。
Here is a screenshot of what I checked when adding the file:
这是我在添加文件时检查的屏幕截图:
So I have made sure that it is added to all targets and that the file is in the root directory of the project, alongside the xcodeproj
and xcworkspace
files, as per the instructions on the Google developer guide.
因此,我确保按照 Google 开发人员指南中的说明,将其添加到所有目标中,并且该文件位于项目的根目录中,与xcodeproj
和xcworkspace
文件一起。
I should also mention that this is a SpriteBuilder project, but I don't think that has anything to do with this. Also this was the first Cocoa Pod that I added, but all seems fine with that as the project builds and can find all the Google headers it needs.
我还应该提到这是一个 SpriteBuilder 项目,但我认为这与此无关。这也是我添加的第一个 Cocoa Pod,但随着项目的构建,一切似乎都很好,并且可以找到它需要的所有 Google 标头。
回答by Dmitry Isaev
I was also stuck with this strange piece of code. But you don't need it! Just remove configureWithError and all these things.
我也被这段奇怪的代码困住了。但你不需要它!只需删除 configureWithError 和所有这些东西。
All you need is:
所有你需要的是:
[[GAI sharedInstance] trackerWithTrackingId:@"UA-11111111-2"];
[GAI sharedInstance].trackUncaughtExceptions = YES;
Somewhere inside didFinishLaunchingWithOptions. (It's from the previous GA version, right?) So, that's it! Then, do anything you want in your app:
didFinishLaunchingWithOptions 里面的某个地方。(它来自之前的 GA 版本,对吗?)所以,就是这样!然后,在你的应用程序中做任何你想做的事情:
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker set:kGAIScreenName value:@"start screen"];
[tracker send:[[GAIDictionaryBuilder createScreenView] build]];
My Podfile looks like this:
我的 Podfile 看起来像这样:
source 'https://github.com/CocoaPods/Specs.git'
pod 'Google/Analytics', '~> 1.0.0'
It works!
有用!
回答by jaskiratjd
If you already integrate google signIn it provide plist for accessing the login service detail of your app. It means when you try to integrate the analytic you dont need to add the new GoogleService-Info.plist. You just add the following keys which are missing in the existing plist file.
如果您已经集成了 google signIn,它会提供 plist 以访问您的应用程序的登录服务详细信息。这意味着当您尝试集成分析时,您不需要添加新的 GoogleService-Info.plist。您只需添加现有 plist 文件中缺少的以下键。