Skip to content

Commit

Permalink
Demo: Restart Rollbar with new access token without requiring submiss…
Browse files Browse the repository at this point in the history
…ion (#272)
  • Loading branch information
matux authored Mar 21, 2023
1 parent 0265129 commit 51536dc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Demos/iosAppSwift/iosAppSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 46;
CURRENT_PROJECT_VERSION = 50;
DEVELOPMENT_ASSET_PATHS = "\"iosAppSwift/Preview Content\"";
DEVELOPMENT_TEAM = 9P5JVC2F34;
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -320,7 +320,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 46;
CURRENT_PROJECT_VERSION = 50;
DEVELOPMENT_ASSET_PATHS = "\"iosAppSwift/Preview Content\"";
DEVELOPMENT_TEAM = 9P5JVC2F34;
ENABLE_PREVIEWS = YES;
Expand Down
15 changes: 12 additions & 3 deletions Demos/iosAppSwift/iosAppSwift/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ struct ContentView: View {
.tint(.blue)
}

func restart() {
func restartIfValid(_ accessToken: String) {
guard accessToken.isValid else { return }

let config = Rollbar.configuration().mutableCopy()
config.destination.accessToken = accessToken
Rollbar.update(withConfiguration: config)

Rollbar.infoMessage("Rollbar Apple SDK access token changed.")

print("Rollbar Apple SDK access token changed to \(accessToken)")
}

var body: some View {
Expand All @@ -40,7 +45,7 @@ struct ContentView: View {
.multilineTextAlignment(.center)
.textCase(.lowercase)
.lineLimit(1)
.onSubmit(accessToken.isValid ? restart : {})
.onChange(of: accessToken, perform: restartIfValid)
.padding(.bottom)

ScrollView {
Expand Down Expand Up @@ -88,10 +93,14 @@ struct Example {

/// Some different ways to explicitly log an error to Rollbar.
func manualLogging() {
let extraInfo = ["item_1": "value_1", "item_2": "value_2"]
Rollbar.infoMessage(
"Rollbar is up and running! Enjoy your remote error and log monitoring...",
data: ["key_x": "value_x", "key_y": "value_y"])

Rollbar.log(.error, message: "My log message")

let extraInfo = ["item_1": "value_1", "item_2": "value_2"]

Rollbar.log(
.error,
error: ExampleError.invalidInput,
Expand Down
5 changes: 0 additions & 5 deletions Demos/iosAppSwift/iosAppSwift/iosAppSwiftApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ class AppDelegate: NSObject, UIApplicationDelegate {
// Initialize a Rollbar shared instance with a crash collector
Rollbar.initWithConfiguration(config)

// Note the ability to add aditional key/value pairs to the occurrence data for extra context
Rollbar.infoMessage(
"Rollbar is up and running! Enjoy your remote error and log monitoring...",
data: ["key_x": "value_x", "key_y": "value_y"])

return true
}
}
Expand Down

0 comments on commit 51536dc

Please sign in to comment.