From 51536dcadfb5a8f205b09acf567392e59f867c57 Mon Sep 17 00:00:00 2001 From: Matias Pequeno Date: Mon, 20 Mar 2023 21:21:32 -0300 Subject: [PATCH] Demo: Restart Rollbar with new access token without requiring submission (#272) --- .../iosAppSwift.xcodeproj/project.pbxproj | 4 ++-- Demos/iosAppSwift/iosAppSwift/ContentView.swift | 15 ++++++++++++--- .../iosAppSwift/iosAppSwift/iosAppSwiftApp.swift | 5 ----- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Demos/iosAppSwift/iosAppSwift.xcodeproj/project.pbxproj b/Demos/iosAppSwift/iosAppSwift.xcodeproj/project.pbxproj index 55c87465..92f04ebb 100644 --- a/Demos/iosAppSwift/iosAppSwift.xcodeproj/project.pbxproj +++ b/Demos/iosAppSwift/iosAppSwift.xcodeproj/project.pbxproj @@ -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; @@ -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; diff --git a/Demos/iosAppSwift/iosAppSwift/ContentView.swift b/Demos/iosAppSwift/iosAppSwift/ContentView.swift index 72ade803..f463c847 100644 --- a/Demos/iosAppSwift/iosAppSwift/ContentView.swift +++ b/Demos/iosAppSwift/iosAppSwift/ContentView.swift @@ -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 { @@ -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 { @@ -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, diff --git a/Demos/iosAppSwift/iosAppSwift/iosAppSwiftApp.swift b/Demos/iosAppSwift/iosAppSwift/iosAppSwiftApp.swift index 1f2d6975..8016c55b 100644 --- a/Demos/iosAppSwift/iosAppSwift/iosAppSwiftApp.swift +++ b/Demos/iosAppSwift/iosAppSwift/iosAppSwiftApp.swift @@ -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 } }