I followed this Google developer guide to 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:
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:
*** 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.
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.
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.
I put the GoogleService-Info.plist in my directory, but it still isn't working. Karan. S Karan. S Show activity on this post. You must drag and drop the GoogleService-Info.plist file into your project in a location such as Shared Resources. When you have successfully added the file, you should also make sure to include it in the project build:
This article shows you how to add the GoogleServices-Info.plist file the right way. 1. Open the ios folder of your project with XCode. 2. Right click on Runner in the left-hand column then select Add Files to Runner from the menu. 3. Select the GoogleServices-Info.plist file from your computer and click on the Add button.
If you just copy and paste this file into the Runner folder then there will be an error when running your application on an iOS simulator or a connected iPhone. This article shows you how to add the GoogleServices-Info.plist file the right way.
The file name must be exactly GoogleService-Info.plist common misspellings include GoogleServices-Info.plist and GoogleService-info.plist - case sensitive and exactly named only will work. Show activity on this post. I faced the same problem.
I was also stuck with this strange piece of code. But you don't need it! Just remove configureWithError and all these things.
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:
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker set:kGAIScreenName value:@"start screen"];
[tracker send:[[GAIDictionaryBuilder createScreenView] build]];
My Podfile looks like this:
source 'https://github.com/CocoaPods/Specs.git'
pod 'Google/Analytics', '~> 1.0.0'
It works!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With