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.
<PlatformSection supported={["apple.visionos"]}>
The support for visionOS is currently experimental, which means it may have bugs. We recognize the irony.
<PlatformSection notSupported={["apple.tvos", "apple.watchos", "apple.visionos"]}>
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.
<PlatformSection notSupported={["apple.ios", "apple.macos"]}>
In addition to capturing errors, you can monitor interactions between multiple services or applications by enabling tracing.
Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.
<PlatformSection notSupported={["apple.tvos", "apple.watchos", "apple.visionos"]}>
<OnboardingOptionButtons options={['error-monitoring', 'performance', 'profiling', 'session-replay', 'logs']}/>
<PlatformSection notSupported={["apple.ios", "apple.macos"]}>
<OnboardingOptionButtons options={['error-monitoring', 'performance', 'logs']}/>
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.
<PlatformSection notSupported={["apple.ios"]}>
We recommend installing the SDK with Swift Package Manager (SPM), but we also support alternate installation methods. To integrate Sentry into your Xcode project, open your App in Xcode and open File > Add Packages. Then add the SDK by entering the git repo url in the top right search field:
https://github.com/getsentry/sentry-cocoa.git
<PlatformSection supported={["apple.ios"]}> We recommend installing the SDK through our Sentry Wizard by running the following command inside your project directory:
brew install getsentry/tools/sentry-wizard && sentry-wizard -i iosThis 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.
- Install the Sentry SDK via Swift Package Manager
- Update your
AppDelegateor SwiftUI App Initializer with the default Sentry configuration and an example error - Add a new
Upload Debug Symbolsphase to yourxcodebuildbuild script - Create
.sentryclircwith 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
<PlatformSection notSupported={[ "apple.watchos"]}>
To capture all errors, we recommend to initialize the SDK on the main thread as soon as possible, such as in your AppDelegate application:didFinishLaunchingWithOptions method:
<PlatformSection notSupported={["apple.tvos", "apple.watchos", "apple.visionos"]}>
import Sentry
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
SentrySDK.start { options in
options.dsn = "___PUBLIC_DSN___"
options.debug = true // Enabled debug when first installing is always helpful
// Adds IP for users.
// For more information, visit: https://docs.sentry.io/platforms/apple/data-management/data-collected/
options.sendDefaultPii = true
// ___PRODUCT_OPTION_START___ performance
// Set tracesSampleRate to 1 to capture 100% of transactions for performance monitoring.
// We recommend adjusting this value in production.
options.tracesSampleRate = 1
// ___PRODUCT_OPTION_END___ performance
// ___PRODUCT_OPTION_START___ profiling
options.configureProfiling = {
$0.lifecycle = .trace
$0.sessionSampleRate = 1
}
// ___PRODUCT_OPTION_END___ profiling
// ___PRODUCT_OPTION_START___ session-replay
// Record session replays for 100% of errors and 10% of sessions
options.sessionReplay.onErrorSampleRate = 1.0
options.sessionReplay.sessionSampleRate = 0.1
// ___PRODUCT_OPTION_END___ session-replay
// ___PRODUCT_OPTION_START___ logs
// Enable logs to be sent to Sentry
options.enableLogs = true
// ___PRODUCT_OPTION_END___ logs
}
return true
}@import Sentry;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[SentrySDK startWithConfigureOptions:^(SentryOptions *options) {
options.dsn = @"___PUBLIC_DSN___";
options.debug = YES; // Enabled debug when first installing is always helpful
// Adds IP for users.
// For more information, visit: https://docs.sentry.io/platforms/apple/data-management/data-collected/
options.sendDefaultPii = YES;
// ___PRODUCT_OPTION_START___ performance
// Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
// We recommend adjusting this value in production.
options.tracesSampleRate = @1.f;
// ___PRODUCT_OPTION_END___ performance
// ___PRODUCT_OPTION_START___ profiling
options.configureProfiling = ^(SentryProfileOptions *profiling) {
profiling.lifecycle = SentryProfileLifecycleTrace;
profiling.sessionSampleRate = 1.f;
};
// ___PRODUCT_OPTION_END___ profiling
// ___PRODUCT_OPTION_START___ session-replay
// Record session replays for 100% of errors and 10% of sessions
options.sessionReplay.onErrorSampleRate = 1.0;
options.sessionReplay.sessionSampleRate = 0.1;
// ___PRODUCT_OPTION_END___ session-replay
// ___PRODUCT_OPTION_START___ logs
// Enable logs to be sent to Sentry
options.enableLogs = YES;
// ___PRODUCT_OPTION_END___ logs
}];
return YES;
}import Sentry
@main
struct SwiftUIApp: App {
init() {
SentrySDK.start { options in
options.dsn = "___PUBLIC_DSN___"
options.debug = true // Enabled debug when first installing is always helpful
// Adds IP for users.
// For more information, visit: https://docs.sentry.io/platforms/apple/data-management/data-collected/
options.sendDefaultPii = true
// ___PRODUCT_OPTION_START___ performance
// Set tracesSampleRate to 1 to capture 100% of transactions for performance monitoring.
// We recommend adjusting this value in production.
options.tracesSampleRate = 1
// ___PRODUCT_OPTION_END___ performance
// ___PRODUCT_OPTION_START___ profiling
options.configureProfiling = {
$0.lifecycle = .trace
$0.sessionSampleRate = 1
}
// ___PRODUCT_OPTION_END___ profiling
// ___PRODUCT_OPTION_START___ session-replay
// Record session replays for 100% of errors and 10% of sessions
options.sessionReplay.onErrorSampleRate = 1.0
options.sessionReplay.sessionSampleRate = 0.1
// ___PRODUCT_OPTION_END___ session-replay
// ___PRODUCT_OPTION_START___ logs
// Enable logs to be sent to Sentry
options.enableLogs = true
// ___PRODUCT_OPTION_END___ logs
}
}
}<PlatformSection notSupported={["apple.ios", "apple.macos", "apple.watchos"]}>
import Sentry
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
SentrySDK.start { options in
options.dsn = "___PUBLIC_DSN___"
options.debug = true // Enabled debug when first installing is always helpful
// Adds IP for users.
// For more information, visit: https://docs.sentry.io/platforms/apple/data-management/data-collected/
options.sendDefaultPii = true
// ___PRODUCT_OPTION_START___ performance
// Set tracesSampleRate to 1 to capture 100% of transactions for performance monitoring.
// We recommend adjusting this value in production.
options.tracesSampleRate = 1
// ___PRODUCT_OPTION_END___ performance
// ___PRODUCT_OPTION_START___ profiling
options.configureProfiling = {
$0.lifecycle = .trace
$0.sessionSampleRate = 1
}
// ___PRODUCT_OPTION_END___ profiling
// ___PRODUCT_OPTION_START___ logs
// Enable logs to be sent to Sentry
options.enableLogs = true
// ___PRODUCT_OPTION_END___ logs
}
return true
}@import Sentry;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[SentrySDK startWithConfigureOptions:^(SentryOptions *options) {
options.dsn = @"___PUBLIC_DSN___";
options.debug = YES; // Enabled debug when first installing is always helpful
// Adds IP for users.
// For more information, visit: https://docs.sentry.io/platforms/apple/data-management/data-collected/
options.sendDefaultPii = YES;
// ___PRODUCT_OPTION_START___ performance
// Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
// We recommend adjusting this value in production.
options.tracesSampleRate = @1.f;
// ___PRODUCT_OPTION_END___ performance
// ___PRODUCT_OPTION_START___ profiling
options.configureProfiling = ^(SentryProfileOptions *profiling) {
profiling.lifecycle = SentryProfileLifecycleTrace;
profiling.sessionSampleRate = 1.f;
};
// ___PRODUCT_OPTION_END___ profiling
// ___PRODUCT_OPTION_START___ logs
// Enable logs to be sent to Sentry
options.enableLogs = YES;
// ___PRODUCT_OPTION_END___ logs
}];
return YES;
}import Sentry
@main
struct SwiftUIApp: App {
init() {
SentrySDK.start { options in
options.dsn = "___PUBLIC_DSN___"
options.debug = true // Enabled debug when first installing is always helpful
// Adds IP for users.
// For more information, visit: https://docs.sentry.io/platforms/apple/data-management/data-collected/
options.sendDefaultPii = true
// ___PRODUCT_OPTION_START___ performance
// Set tracesSampleRate to 1 to capture 100% of transactions for performance monitoring.
// We recommend adjusting this value in production.
options.tracesSampleRate = 1
// ___PRODUCT_OPTION_END___ performance
// ___PRODUCT_OPTION_START___ profiling
options.configureProfiling = {
$0.lifecycle = .trace
$0.sessionSampleRate = 1
}
// ___PRODUCT_OPTION_END___ profiling
// ___PRODUCT_OPTION_START___ logs
// Enable logs to be sent to Sentry
options.enableLogs = true
// ___PRODUCT_OPTION_END___ logs
}
}
}<PlatformSection supported={[ "apple.watchos"]}>
To capture all errors, we recommend to initialize the SDK on the main thread as soon as possible such as in your WKExtensionDelegate.applicationDidFinishLaunching method:
import Sentry
func applicationDidFinishLaunching() {
SentrySDK.start { options in
options.dsn = "___PUBLIC_DSN___"
options.debug = true // Enabled debug when first installing is always helpful
// Adds IP for users.
// For more information, visit: https://docs.sentry.io/platforms/apple/data-management/data-collected/
options.sendDefaultPii = true
// ___PRODUCT_OPTION_START___ performance
// Set tracesSampleRate to 1 to capture 100% of transactions for performance monitoring.
// We recommend adjusting this value in production.
options.tracesSampleRate = 1
// ___PRODUCT_OPTION_END___ performance
// ___PRODUCT_OPTION_START___ logs
// Enable logs to be sent to Sentry
options.enableLogs = true
// ___PRODUCT_OPTION_END___ logs
}
}<PlatformSection supported={[ "apple.macos"]}>
On macOS, the Sentry Apple SDK can't capture uncaught exceptions out of the box, therefore we recommend enabling enableUncaughtNSExceptionReporting in your SentryOptions. Alternatively, you can use the SentryCrashExceptionApplication class. Please visit capturing uncaught exceptions for more information.
import Sentry
SentrySDK.start { options in
options.dsn = "___PUBLIC_DSN___"
options.enableUncaughtNSExceptionReporting = true
}@import Sentry;
[SentrySDK startWithConfigureOptions:^(SentryOptions *options) {
options.dsn = @"___PUBLIC_DSN___";
options.enableUncaughtNSExceptionReporting = YES;
}];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.
import Sentry
do {
try aMethodThatMightFail()
} catch {
SentrySDK.capture(error: error)
}@import Sentry;
NSError *error = nil;
[self aMethodThatMightFail:&error]
if (error) {
[SentrySDK captureError:error];
}- Explore practical guides on what to monitor, log, track, and investigate after setup
- Learn more about Sentry's Apple SDK features
- Add readable stack traces to errors
- Add Apple Privacy manifest
Yes, you can initialize the SDK from a background thread, but this is not recommended. Some initialization steps, like collecting view hierarchy information, must still run on the main thread. Initializing on the main thread also ensures reliable detection of app launch crashes.