Search code examples
swiftcrashlyticstwitter-fabric

Answers By Crashlytics - adding custom event


I have an app using Crashlytics with Answers. Both are working right, and I am seeing events that are built into the framework being tracked.

I am trying to add a custom event, by using the following line of code in my View Controller:

Answers.logCustomEventWithName("Flight Complete", customAttributes: nil)

My issue is that the compiler doesn't recognize the Answers object. It just tells me "Use of unresolved identifier "Answers"" Which makes sense because I've never declared it.

I am unsure of where or how to create this Answers object, as it is already integrated and working for default events. Does anyone know where I should declare it for use across the app? (AppDelegate?) or what the declaration looks like? They don't show it in the docs.

Thanks

UPDATE: Here's what I've tried adding to AppDelegate but still not recognizing "Answers" object...

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    Fabric.with([Crashlytics.self, Answers.self])

Solution

  • Wanted to close this question since it is now answered from the comments:

    I failed to call

    import Crashlytics
    

    At the top of the view controller like a complete idiot.

    Also, I had added

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    Fabric.with([Crashlytics.self, Answers.self])
    

    When it is correct as:

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    Fabric.with([Crashlytics.self])
    

    Answers is included in the Crashlytics call.