Test your Crashlytics implementation

Force a crash to test your implementation

  1. Add code to your app that you can use to force a test crash.

    You can use the following code to add a button to your app that, when pressed, causes a crash. The button is labeled "Test Crash".

    SwiftUI

    Button("Crash") {
      fatalError("Crash was triggered")
    }
    

    UIKit

    Swift

    import UIKit
    
    class ViewController: UIViewController {
      override func viewDidLoad() {
          super.viewDidLoad()
    
          // Do any additional setup after loading the view, typically from a nib.
    
          let button = UIButton(type: .roundedRect)
          button.frame = CGRect(x: 20, y: 50, width: 100, height: 30)
          button.setTitle("Test Crash", for: [])
          button.addTarget(self, action: #selector(self.crashButtonTapped(_:)), for: .touchUpInside)
          view.addSubview(button)
      }
    
      @IBAction func crashButtonTapped(_ sender: AnyObject) {
          let numbers = [0]
          let _ = numbers[1]
      }
    }
    

    Objective-C

    #import "ViewController.h"
    
    @implementation ViewController
    ‐ (void)viewDidLoad {
        [super viewDidLoad];
    
        // Do any additional setup after loading the view, typically from a nib.
    
        UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        button.frame = CGRectMake(20, 50, 100, 30);
        [button setTitle:@"Test Crash" forState:UIControlStateNormal];
        [button addTarget:self action:@selector(crashButtonTapped:)
            forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:button];
    }
    
    ‐ (IBAction)crashButtonTapped:(id)sender {
        @[][1];
    }
    
    @end
    
  2. Build and run your app in Xcode with the Xcode debugger disconnected.

    1. Click Build and then run the current scheme to build your app on a test device or simulator.

    2. Wait until your app is running, then click Stop running the scheme or action to close the initial instance of your app. This initial instance included the debugger that interferes with Crashlytics.

  3. Force the test crash in order to send your app's first crash report:

    1. Open your app from the home screen of your test device or simulator.

    2. In your app, press the "Test Crash" button that you added using the code above.

    3. After your app crashes, run it again from Xcode so that your app can send the crash report to Firebase.

  4. Go to the Crashlytics dashboard of the Firebase console to see your test crash.

If you've refreshed the console and you're still not seeing the test crash after five minutes, try enabling debug logging (next section).

Enable debug logging for Crashlytics

If you don't see your test crash in the Crashlytics dashboard, you can use debug logging for Crashlytics to help track down the problem.

  1. Enable debug logging:

    1. In Xcode, select Product > Scheme > Edit scheme.

    2. Select Run from the left menu, then select the Arguments tab.

    3. In the Arguments Passed on Launch section, add -FIRDebugEnabled.

  2. Force a test crash. The first section on this page describes how to do this.

  3. Within your logs, search for a log message from Crashlytics that contains the following string, which verifies that your app is sending crashes to Firebase.

    Completed report submission

If you don't see this log or your test crash in the Crashlytics dashboard of the Firebase console after five minutes, reach out to Firebase Support with a copy of your log output so that we can help you troubleshoot further.

Next steps