Upgrade from 4.x to 5.x
Learn about migrating from Sentry Cocoa SDK 4.x to 5.x.
The samples below illustrate how the SDK works:
Example in 4.x:
Copied
do {
Client.shared = try Client(dsn: "___PUBLIC_DSN___")
try Client.shared?.startCrashHandler()
} catch let error {
print("\(error)")
}
do {
Client.shared = try Client(dsn: "___PUBLIC_DSN___")
try Client.shared?.startCrashHandler()
} catch let error {
print("\(error)")
}
NSError *error = nil;
SentryClient *client = [[SentryClient alloc] initWithDsn:@"___PUBLIC_DSN___" didFailWithError:&error];
SentryClient.sharedClient = client;
[SentryClient.sharedClient startCrashHandlerWithError:&error];
if (nil != error) {
NSLog(@"%@", error);
}
Example in 5.x:
Copied
SentrySDK.start(options: [
"dsn": "___PUBLIC_DSN___",
"debug": true
])
SentrySDK.start(options: [
"dsn": "___PUBLIC_DSN___",
"debug": true
])
[SentrySDK startWithOptions:@{
@"dsn": @"___PUBLIC_DSN___",
@"debug": @(YES)
}];
Example in 4.x:`
Copied
Client.shared?.breadcrumbs.add(Breadcrumb(level: .info, category: "test"))
Client.shared?.breadcrumbs.add(Breadcrumb(level: .info, category: "test"))
[SentryClient.sharedClient.breadcrumbs addBreadcrumb:[[SentryBreadcrumb alloc] initWithLevel:kSentrySeverityInfo category:@"test"]];
Example in 5.x:
Copied
SentrySDK.addBreadcrumb(Breadcrumb(level: .info, category: "test"))
SentrySDK.addBreadcrumb(Breadcrumb(level: .info, category: "test"))
[SentrySDK addBreadcrumb:[[SentryBreadcrumb alloc] initWithLevel:kSentrySeverityInfo category:@"test"]];
Example in 4.x:
Copied
let event = Event(level: .debug)
event.message = "Test Message"
event.environment = "staging"
event.extra = ["ios": true]
Client.shared?.send(event: event)
let event = Event(level: .debug)
event.message = "Test Message"
event.environment = "staging"
event.extra = ["ios": true]
Client.shared?.send(event: event)
SentryEvent *event = [[SentryEvent alloc] initWithLevel:kSentrySeverityDebug];
event.message = @"Test Message";
event.environment = @"staging";
event.extra = @{@"ios": @(YES)};
[SentryClient.sharedClient sendEvent:event withCompletionHandler:nil];
Example in 5.x:
Copied
SentrySDK.capture(message: "Test Message") { (scope) in
scope.setEnvironment("staging")
scope.setExtras(["ios": true])
let u = Sentry.User(userId: "1")
u.email = "tony@example.com"
scope.setUser(u)
}
SentrySDK.capture(message: "Test Message") { (scope) in
scope.setEnvironment("staging")
scope.setExtras(["ios": true])
let u = Sentry.User(userId: "1")
u.email = "tony@example.com"
scope.setUser(u)
}
[SentrySDK captureMessage:@"Test Message" withScopeBlock:^(SentryScope * _Nonnull scope) {
[scope setEnvironment:@"staging"];
[scope setExtras:@{@"ios": @(YES)}];
SentryUser *user = [[SentryUser alloc] initWithUserId:@"1"];
user.email = @"tony@example.com";
[scope setUser:user];
}];
Example in 4.x:
Copied
let u = User(userId: "1")
u.email = "tony@example.com"
Client.shared?.user = user
let u = User(userId: "1")
u.email = "tony@example.com"
Client.shared?.user = user
SentryUser *user = [[SentryUser alloc] initWithUserId:@"1"];
user.email = @"tony@example.com";
SentryClient.sharedClient.user = user;
Example in 5.x:
Copied
let u = Sentry.User(userId: "1")
u.email = "tony@example.com"
SentrySDK.setUser(u)
let u = Sentry.User(userId: "1")
u.email = "tony@example.com"
SentrySDK.setUser(u)
SentryUser *user = [[SentryUser alloc] initWithUserId:@"1"];
user.email = @"tony@example.com";
[SentrySDK setUser:user];
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").