iOS

On this page, we get you up and running with Sentry's Apple SDK, which will automatically report errors and exceptions in your application.

If you don't already have an account and Sentry project established, head over to sentry.io, then return to this page.

Sentry captures data by using an SDK within your application's runtime. These are platform-specific and allow Sentry to have a deep understanding of how your application works.

In addition to capturing errors, you can monitor interactions between multiple services or applications by enabling tracing. You can also collect and analyze performance profiles from real users with profiling. To enable tracing and/or profiling, click the corresponding checkmarks to get the code snippets.

We recommend installing the SDK through our Sentry Wizard by running the following command inside your project directory:

Copied
brew install getsentry/tools/sentry-wizard && sentry-wizard -i ios

This will patch your project and configure the SDK. You'll only need to patch the project once, then you'll be able to add the patched files to your version control system. If you prefer, you can also set up the SDK manually or follow the instructions below to adapt the configuration.

The following tasks will be performed by the Sentry Wizard

  • Install the Sentry SDK via Swift Package Manager or Cocoapods
  • Update your AppDelegate or SwiftUI App Initializer with the default Sentry configuration and an example error
  • Add a new Upload Debug Symbols phase to your xcodebuild build script
  • Create .sentryclirc with an auth token to upload debug symbols (this file is automatically added to .gitignore)
  • If you're using Fastlane, a lane for uploading debug symbols to Sentry will be added

To capture all errors, initialize the SDK as soon as possible, such as in your AppDelegate application:didFinishLaunchingWithOptions method:

Copied
import Sentry

func application(_ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    SentrySDK.start { options in
        options.dsn = "https://examplePublicKey@o0.ingest.sentry.io/0"
        options.debug = true // Enabled debug when first installing is always helpful

        // Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
        // We recommend adjusting this value in production.
        options.tracesSampleRate = 1.0

        // Sample rate for profiling, applied on top of TracesSampleRate.
        // We recommend adjusting this value in production.
        options.profilesSampleRate = 1.0
    }

    return true
}

Verify that your app is sending events to Sentry by adding the following snippet, which includes an intentional error. You should see the error reported in Sentry within a few minutes.

To verify crashes, ensure you run your application without a debugger attached. Otherwise, the SDK won't capture the crash.

Copied
import Sentry

do {
    try aMethodThatMightFail()
} catch {
    SentrySDK.capture(error: error)
}

Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").