TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | May 2016 |
SPMSupports SPM | ✗ |
Maintained by Tommy Mikalsen.
Swift client for Sentry.
The easiest way is to use CocoaPods. It takes care of all of the setup, required frameworks and third party dependencies:
Steps
pod 'RavenSwift'
pod install
Alternatively, you can install manually.
git clone git://github.com/getsentry/raven-swift
RavenClient.swift
and RavenConfig.swift
files to your project. Check both "copy items into destination group's folder" and your target.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:
cd [your project root]
git submodule add git://github.com/getsentry/raven-swift
RavenClient.swift
and RavenConfig.swift
files to your project. Uncheck the "copy items into destination group's folder" box, do check your target.UncaughtExceptionHandler.h
and .m
files to your project. Check both "copy items into destination group's folder" and your target.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__)
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.
Have a bug? Please create an issue on GitHub!
https://github.com/getsentry/raven-swift/issues
raven-swift is an open source project and your contribution is very much appreciated.
raven-swift is available under the MIT license. See the LICENSE file for more info.