CrashButtonView.swift 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //
  2. // Copyright 2024 Google LLC
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. import FirebaseCrashlytics
  17. import Foundation
  18. import SwiftUI
  19. struct CrashButtonView: View {
  20. var body: some View {
  21. var counter = 0
  22. NavigationView {
  23. VStack(
  24. alignment: .leading,
  25. spacing: 10
  26. ) {
  27. Button(action: {
  28. Crashlytics.crashlytics().setUserID("ThisIsABot")
  29. }) {
  30. Text("Set User Id")
  31. }
  32. Button(action: {
  33. assertionFailure("Throw a Crash")
  34. }) {
  35. Text("Crash")
  36. }
  37. Button(action: {
  38. Crashlytics.crashlytics().record(error: NSError(
  39. domain: "This is a test non-fatal",
  40. code: 400
  41. ))
  42. }) {
  43. Text("Record Non-fatal event")
  44. }
  45. Button(action: {
  46. Crashlytics.crashlytics().setCustomValue(counter, forKey: "counter " + String(counter))
  47. let i = counter
  48. counter = i + 1
  49. }) {
  50. Text("Set custom key")
  51. }
  52. }
  53. .navigationTitle("Crashlytics Example")
  54. }
  55. }
  56. }