0

As Parse crash report is depreciating, we are moving to Google Analytics. I follow the guide to and receive view tracking and exception reports successfully.

here is how I setup the GA

// Configure tracker from GoogleService-Info.plist.
        var configureError:NSError?
        GGLContext.sharedInstance().configureWithError(&configureError)
        assert(configureError == nil, "Error configuring Google services: \(configureError)")

        // Optional: configure GAI options.
        let gai = GAI.sharedInstance()
        gai.trackerWithTrackingId("UA-XXXXXX-1")
        gai.trackUncaughtExceptions = true  // report uncaught exceptions
        gai.dispatchInterval = 1
        gai.defaultTracker.allowIDFACollection = true

        #if DEBUG
            gai.logger.logLevel = GAILogLevel.Verbose  // remove before app release
        #endif

And I tried to make a crash by (in AppDelegate.swift didFinishLaunchingWithOptions ):

delay(20.0) { () -> () in
    let _ = [String]()[10];
}

And I can't get any crash report from GA dashboard.

I've tried to move this line to an IBAction, but failed.

My testing steps:

  1. debug on device ->(20s)-> crash

  2. debug on device 2nd time ->(20s)-> crash

  3. run the app without debugging ->(20s)-> crash

  4. run the app without debugging ->(20s)-> crash

Horst
  • 1,733
  • 15
  • 20

1 Answers1

1

It turns out that Google Analytics only supports reporting of uncaught Objective-C exceptions. It does not report Swift throws. The following creates a Swift throw (and is not reported by GA):

    let crashArray:Array = [0]
    crashArray[1]

The following does create an Objective-C exception and is reported by GA:

    let array = NSArray()
    let _ = array.objectAtIndex(99)

Some useful information here...

How should I use NSSetUncaughtExceptionHandler in Swift

We can force an Objective-C exception from within Swift by using the following command (i.e. from within a catch).

    let error = NSError(domain: "Some error.", code: 0, userInfo: nil)
    NSException.raise("Exception", format:"Error: %@", arguments:getVaList([error ?? "nil"]))

There is not a way I can find to automatically capture all throws and relay them as an Objective-C exception.

Community
  • 1
  • 1
Justin Domnitz
  • 3,217
  • 27
  • 34
  • Agree. That's why I move to crashlytics. They do really well for swift crash report while comparing with GA. – Horst Apr 01 '16 at 03:42