TYPE ON THE FIELD BELOW AND PRESS ENTER TO SEARCH FOR BLOG POSTS

Crashlytics help spending less time on fixing crashes without looping in to various scenarios. It provides deep, actionable insights and even the exact line of code where the app crashed on. It gives you powerful crash reporting, with one click by enabling real-time analytics that helps to understand what’s happening in the app.

Installing Crashlytics via CocoaPods:

If you don’t already have a Fabric account, request an invitation from a member of your company’s Fabric organization or sign up and create a new organization. A Fabric account is needed before you can install any of their kits.

Add the Kit to Podfile:

The Crashlytics Kit can be installed using CocoaPods.

Add following to podFile.

 pod 'Fabric'
 pod 'Crashlytics'

To continue, run the following command in terminal

 pod install

Crashlytics is installed successfully.

Add a Run Script Build Phase:

In the Project Navigator, click on your project and add a new run script build phase

Then Click Run Script,

add  "${PODS_ROOT}/Fabric/run"

Login to Fabric to have Fabric API key generated automatically.

Add Your API Key:

In the Project Navigator, right click on “Info.plist”, and “Open as” → “Source Code”

Add the following code to info.plist.

Fabric
APIKey
Kits
KitInfo
KitName
Crashlytics

Login to Fabric to have Fabric API key generated automatically.

Initialize Your Kit:

import UIKit
import Fabric
import Crashlytics
 
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptionslaunchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
Fabric.with([Crashlytics.self])
      return true
    }
}

Code Example:

Force a Crash:
Test out Crashlytics by making app crash.

Call the crash method:
Add a button to view that calls Crashlytics.sharedInstance().crash() when it’s pressed.

import UIKit
import Crashlytics
 
class ViewController: UIViewController {
 
    override funcviewDidLoad() {
        super.viewDidLoad()
        let button = UIButton(type: .roundedRect)
        button.frame = CGRect(x: 20, y: 50, width: 100, height: 30)
        button.setTitle("Crash", for: [])
        button.addTarget(self, action: #selector(self.crashButtonTapped(_:)), for: .touchUpInside)
        view.addSubview(button)
        }
 
        @IBActionfunccrashButtonTapped(_ sender: AnyObject) {
        Crashlytics.sharedInstance().crash()
        }
  }

Try it out!

Crashlytics doesn’t capture crashes if a debugger is attached at launch, so to see the crash in action need to follow these steps:

  1. Run app from Xcode to install it on the simulator or your device
  2. Press the Stop button in Xcode to quit it
  3. Launch app from the home screen to run it without the debugger
  4. Press the “Crash” button to trigger the crash
  5. Run the app again from Xcode so it can deliver the recorded crash to Crashlytics
    Within a few minutes, you should see the crash appear on Fabric Dashboard.

Ready to Build Your Projects?

The best companies and startups hire our top dev teams, and so can you.
Start a Project
GSM Plus Infotech