Objective-c client for Sentry.
The easiest way is to use CocoaPods. It takes care of all required frameworks and third party dependencies:
pod 'Raven'
Alternatively, you can install manually.
- Get the code:
git clone git://github.com/getsentry/raven-objc
- Drag the
Raven
subfolder 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-objc
- Drag the
Raven
subfolder to your project. Uncheck the "copy items into destination group's folder" box, do check your target.
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:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[RavenClient clientWithDSN:@"[SENTRY_DSN]"];
// [...]
return YES;
}
The first RavenClient
that is initialized is automatically configured as the singleton instance and becomes available via the sharedClient
singleton method:
NSLog(@"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__];
// Recommended macro to send a message with automatic stacktrace:
RavenCaptureMessage(@"TEST %i %@ %f", 1, @"2", 3.0);
Setup a global exception handler:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[RavenClient clientWithDSN:@"https://[public]:[secret]@[server]/[project id]"];
[[RavenClient sharedClient] setupExceptionHandler];
// [...]
return YES;
}
Or, capture a single exception:
@try {
[self performSelector:@selector(nonExistingSelector)];
}
@catch (NSException *exception) {
RavenCaptureException(exception);
}
You can also capture errors:
NSError *error;
[[NSFileManager defaultManager] removeItemAtPath:@"some/path" error:&error];
RavenCaptureError(error);
Note: when using the global exception handler, exceptions will be sent the next time the app is started.
raven-objc uses NSJSONSerialization
to generate the JSON payload, if it is available. If your app targets a platform where this class is not available (i.e. iOS < 5.0) you can include one of the following JSON libraries to your project for raven-objc to automatically detect and use.
raven-objc requires ARC support and should run on iOS 4.0 and Mac OS X 10.6.
Have a bug? Please create an issue on GitHub!
https://github.com/getsentry/raven-objc/issues
raven-objc is an open source project and your contribution is very much appreciated.
- Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug.
- Fork the repository on Github and make your changes.
- Make sure to add yourself to AUTHORS and send a pull request.
raven-objc is available under the MIT license. See the LICENSE file for more info.