Latest0.5.0
Homepagehttps://github.com/getsentry/raven-swift
Licensemit
Platformsios 8.0, osx 10.9
Authors, ,

raven-swift

Swift client for Sentry.

Installation

Carthage compatible
CocoaPods

The easiest way is to use CocoaPods. It takes care of all of the setup, required frameworks and third party dependencies:

Steps

  1. Install Cocoapods
  2. Add raven swift to podfile: pod 'RavenSwift'
  3. Install: pod install

Alternatively, you can install manually.

  1. Get the code: git clone git://github.com/getsentry/raven-swift
  2. Drag the RavenClient.swift and RavenConfig.swift files to your project. Check both "copy items into destination group’s folder" and your target.
  3. If you want to set up a global exception handler, drag the UncaughtExceptionHandler.h and .m files to your project. Check both "copy items into destination group’s folder" and your target.

Alternatively you can add this code as a Git submodule:

  1. cd [your project root]
  2. git submodule add git://github.com/getsentry/raven-swift
  3. Drag the RavenClient.swift and RavenConfig.swift files to your project. Uncheck the "copy items into destination group’s folder" box, do check your target.
  4. If you want to set up a global exception handler, drag the UncaughtExceptionHandler.h and .m files to your project. Check both "copy items into destination group’s folder" and your target.

How to get started

Note: If you are using cocoapods, import RavenSwift anywhere the raven client is used

While you are free to initialize as many instances of RavenClient as is appropriate for your application, there is a shared singleton instance that is globally available. This singleton instance is often configured in your app delegate’s application:didFinishLaunchingWithOptions: method:

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

        RavenClient.clientWithDSN("https://30d629f2df9c4fdf8507e1704c09a526:[email protected]/888")

        // [...]
        return true
}

The first RavenClient that is initialized is automatically configured as the singleton instance and becomes available via the sharedClient singleton method:

println("I am your RavenClient singleton : (RavenClient.sharedClient?)")
// Sending a basic message (note, does not include a stacktrace):
RavenClient.sharedClient?.captureMessage("TEST 1 2 3")

// Sending a message with another level and a stacktrace:
RavenClient.sharedClient?.captureMessage("TEST 1 2 3", level: .kRavenLogLevelDebugInfo, method: __FUNCTION__, file: __FILE__, line: __LINE__)

You can also capture errors:

var error: NSError?
NSFileManager.defaultManager().removeItemAtPath("some/path", error: &error)

// Sending basic error 
RavenClient.sharedClient?.captureError(error!)

// Sending error with method, file and line number 
RavenClient.sharedClient?.captureError(error!, method: __FUNCTION__, file: __FILE__, line: __LINE__)

Handling exceptions

If you want a global exception handler, you will need to add this to your bridging header. This step is only required if it is manually installed. Cocoapods will handle this for you:

#import "UncaughtExceptionHandler.h"

Then you can set up a global exception handler:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.

    RavenClient.clientWithDSN("https://[public]:[secret]@[server]/[project id]")

    RavenClient.sharedClient?.setupExceptionHandler()

    return true
}

Note: when using the global exception handler, exceptions will be sent the next time the app is started.

Issues and questions

Have a bug? Please create an issue on GitHub!

https://github.com/getsentry/raven-swift/issues

Contributing

Join the chat at https://gitter.im/getsentry/raven-swift

raven-swift is an open source project and your contribution is very much appreciated.

  1. Check for open issues or open a fresh issue or check Gitter to start a discussion around a feature idea or a bug.
  2. Fork the repository on Github and make your changes.
  3. Make sure to add yourself to AUTHORS and send a pull request.

License

raven-swift is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "RavenSwift",
    "version": "0.5.0",
    "summary": "swift client for sentry",
    "homepage": "https://github.com/getsentry/raven-swift",
    "license": "mit",
    "authors": [
        "Tommy Mikalsen",
        "Erik Sargent",
        "Sean Cheng"
    ],
    "source": {
        "git": "https://github.com/getsentry/raven-swift.git",
        "tag": "0.5.0"
    },
    "platforms": {
        "ios": "8.0",
        "osx": "10.9"
    },
    "source_files": "Raven/**/*.{h,m,swift}",
    "ios": {
        "exclude_files": "Raven/Raven-OSX.h"
    },
    "osx": {
        "exclude_files": "Raven/Raven-iOS.h"
    }
}

Pin It on Pinterest

Share This