Integrate sentry into your swift application.
// AppDelegate.swift import Sentry class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Create a Sentry client and start crash handler do { Client.shared = try Client(dsn: "https://515b3example:5d302example@sentry.io/123456") try Client.shared?.startCrashHandler() } catch let error { print("(error)") // Wrong DSN or KSCrash not installed } return true } . . }
The sentry listener will automagically send the stack trace when the app crashes. But what if you want to send arbitrary messages whenever you want?
// SomeView.swift import Sentry func someFunction() { let tokenEvent = Event(level: .debug) tokenEvent.message = "localToken" tokenEvent.extra = ["localToken": localStorage.value(forKey: "token") as! String] Client.shared?.send(event: tokenEvent) { (error) in // Optional callback after event has been send print("localToken sent") } let someEvent = Event(level: .debug) someEvent.message = "something" someEvent.extra = ["something": "wow so cool"] Client.shared?.send(event: someEvent) { (error) in // Optional callback after event has been send print("someEvent sent") } }
There’s probs more but this is all I used it for so far…