Cocoa

This is the documentation for our official clients for Cocoa (Swift and Objective-C).

Installation

The client (Sentry) can be installed using CocoaPods or Carthage. This is the recommended client for both Swift and Objective-C. If you need support for old versions of iOS that do not support Swift you can use our alternative Sentry-Objc client.

To integrate Sentry into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

target 'YourApp' do
    pod 'Sentry', :git => 'https://github.com/getsentry/sentry-swift.git', :tag => '2.1.1'
end

Afterwards run pod install. In case you encounter problems with dependencies and you are on a newer CocoaPods you might have to run pod repo update first.

In case your project still uses Swift 2.3 you can add these lines at the end of your Podfile which tells your Pods to use Swift 2.3.

post_install do |installer|
  installer.pods_project.build_configurations.each do |config|
    config.build_settings['SWIFT_VERSION'] = '2.3'
    config.build_settings['ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES'] = 'NO'
  end
end

To integrate Sentry into your Xcode project using Carthage, specify it in your Cartfile:

github "getsentry/sentry-swift" "2.1.1"

Run carthage update to build the framework and drag the built Sentry.framework and KSCrash.framework into your Xcode project.

We also provide a prebuilt version for every release which you can download in the releases section on github.

Configuration

To use the client, change your AppDelegate’s application method to instantiate the Sentry client:

import Sentry

func application(application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    // Create a Sentry client and start crash handler
    SentryClient.shared = SentryClient(dsnString: "___DSN___")
    SentryClient.shared?.startCrashHandler()

    return true
}

If you prefer to use Objective-C you can do so like this:

@import Sentry;

[SentryClient setShared:[[SentryClient alloc] initWithDsnString:@"___DSN___"]];
[[SentryClient shared] startCrashHandler];

Note that in case of a real crash make sure to call startCrashHandler before setting any other properties on the client. This guarantees that the stored crash report has the expected properties set.

Debug Symbols

Before you can start capturing crashes you will need to tell Sentry about the debug information by uploading dSYM files. Depending on your setup this can be done in different ways:

Testing a Crash

If you would like to test the crash reporting you will need to cause a crash. While, the seemingly obvious method would be make it crash on launch, this will not give the Sentry client a chance to actually submit the crash report. Instead, we recommend triggering a crash from a button tap.

You can use the following methods to cause a crash:

  • Swift:

    SentryClient.shared?.crash()
    
  • Objective-C:

    [[SentryClient shared] crash];
    

Note that if you crash with a debugger attached nothing will happen.

Crashes are only submitted upon re-launching the application. To test the crashing, close the app and launch it again from the springboard.