使用GoogleService-Info.plist为iOS应用配置Google分析时出错
发布时间:2020-12-14 17:57:32 所属栏目:百科 来源:网络整理
导读:我按照这个 Google developer guide将Google分析添加到使用Cocoa Pods的iOS应用程序中.我添加了GoogleService-Info.plist并将初始化代码放在didFinishLaunchingWithOptions中.该应用程序构建正常,但然后在尝试初始化GA时崩溃.特别是这些代码行: NSError *co
我按照这个
Google developer guide将Google分析添加到使用Cocoa Pods的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,我也会收到错误,这让我相信我没有将文件添加到项目中正确. 这是我在添加文件时检查的屏幕截图: 因此,我已确保将其添加到所有目标,并且该文件位于项目的根目录中,与xcodeproj和xcworkspace文件一起,根据Google开发人员指南中的说明. 我还要提一下,这是一个SpriteBuilder项目,但我认为这与此无关.这也是我添加的第一个Cocoa Pod,但随着项目的构建,它可以找到所需的所有Google标题. 解决方法
我也被这段奇怪的代码困住了.但你不需要它!只需删除configureWithError和所有这些东西.
所有你需要的是: [[GAI sharedInstance] trackerWithTrackingId:@"UA-22222111-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' 有用! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |