0

I'm following the instructions on here to integrate google analytics into my app: https://developers.google.com/analytics/devguides/collection/ios/v3/?ver=swift#get-config

I'm at the point where I need to initialize analytics for my app. I've added this code in my AppDelegate.swift file:

import UIKit
import <Google/Analytics.h>

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions:[NSObject: AnyObject]?) -> Bool {
        **// Configure tracker from GoogleService-Info.plist.
        NSError *configureError;
        [[GGLContext sharedInstance] configureWithError:&configureError];
        NSAssert(!configureError, @"Error configuring Google services: %@", configureError);

        // Optional: configure GAI options.
        GAI *gai = [GAI sharedInstance];
        gai.trackUncaughtExceptions = YES;  // report uncaught exceptions
        gai.logger.logLevel = kGAILogLevelVerbose;  // remove before app release**

    }

I'm getting the following error messages.

  1. For my import <Google/Analytics.h> line, I'm getting this message:'Consecutive statements on a line must be separated by ';'.

  2. For the rest of the code I'm getting several errors, although I simply copied the code in the tutorial into my file. See my screenshot.

enter image description here

dan
  • 9,695
  • 1
  • 42
  • 40

1 Answers1

0

You're getting this issue since you're in a Swift project. You'll need to create an Objective-C bridging header, and add the import statement there. Afterwards, everything should work properly. Check out this SO answer for more details:

https://stackoverflow.com/a/24005242/1784384

Community
  • 1
  • 1
Edward Jiang
  • 2,403
  • 18
  • 13
  • Thanks for the response. I created Objective-C File as Header and added import to the m file. Now I'm getting an error message on the Objective-CBridgingHeader.m file that says:'Expected identified or '('. Additionally, I'm still seeing the same errors on my AppDelegate.swift file from the code that I had pasted in before. – shellmaster Mar 28 '16 at 22:33
  • The bridging header file should be a .h file; make sure you're putting it in there. Also: your code is failing in your AppDelegate because you pasted Objective-C code in there. In your link on Google's website, there's a box that allows you to change it to Swift example code. Do that and you should be golden! – Edward Jiang Mar 28 '16 at 22:37
  • Okay, so I moved this line of code 'import ' to my .h file. I also updated the code in my AppDelegate file. Initially I had selected the Swift radio button on the tutorial but I guess it switched over or I re-opened a new page without noticing. In any case, things are looking better. I'm not seeing an error messages. – shellmaster Mar 28 '16 at 22:57
  • I meant to say that I added the import code to my Bridging-Header.h file. Do I have to create a second .h file as indicated in the stackoverflow response(http://stackoverflow.com/a/24005242/1784384) that you sent me? – shellmaster Mar 28 '16 at 23:08
  • I'm having a tough time envisioning what you'er asking. But you should be able to delete the .m and .h file you created, and leave the bridging header. The bridging header is automatically created when you add Obj-C code, but doesn't detect it when you use Cocoapods. That's why you have to go through this weird process. – Edward Jiang Mar 28 '16 at 23:46
  • I have one .m file and I have my .h file which is called Bridging-Header.h. You're saying that I should remove my .m file and keep my Bridging-Header.h file which has this line of code: import . – shellmaster Mar 29 '16 at 14:41
  • What is your .m file called? – Edward Jiang Mar 29 '16 at 17:24