@@ -20,49 +20,54 @@ import SwiftUI
2020
2121@main
2222struct CrashlyticsSwiftUIExampleApp : App {
23- private var crashlyticsReference = Crashlytics . crashlytics ( )
24- let reachabilityHelper = ReachabilityHelper ( )
23+ private var crashlyticsReference = Crashlytics . crashlytics ( )
24+ #if !os(watchOS)
25+ let reachabilityHelper = ReachabililtyHelper ( )
26+ #endif
2527
26- func setUserInfo( ) {
27- let userInfo = [
28- NSLocalizedDescriptionKey: NSLocalizedString ( " The request failed. " , comment: " " ) ,
29- NSLocalizedFailureReasonErrorKey: NSLocalizedString (
30- " The response returned a 404. " ,
31- comment: " "
32- ) ,
33- NSLocalizedRecoverySuggestionErrorKey: NSLocalizedString (
34- " Does this page exist? " ,
35- comment: " "
36- ) ,
37- " ProductID " : " 123456 " ,
38- " UserID " : " Jane Smith " ,
39- ]
40- let error = NSError ( domain: NSURLErrorDomain, code: - 1001 , userInfo: userInfo)
41- Crashlytics . crashlytics ( ) . record ( error: error)
42- }
28+ func setUserInfo( ) {
29+ let userInfo = [
30+ NSLocalizedDescriptionKey: NSLocalizedString ( " The request failed. " , comment: " " ) ,
31+ NSLocalizedFailureReasonErrorKey: NSLocalizedString (
32+ " The response returned a 404. " ,
33+ comment: " "
34+ ) ,
35+ NSLocalizedRecoverySuggestionErrorKey: NSLocalizedString (
36+ " Does this page exist? " ,
37+ comment: " "
38+ ) ,
39+ " ProductID " : " 123456 " ,
40+ " UserID " : " Jane Smith " ,
41+ ]
42+ let error = NSError ( domain: NSURLErrorDomain, code: - 1001 , userInfo: userInfo)
43+ Crashlytics . crashlytics ( ) . record ( error: error)
44+ }
4345
44- func setCustomValues( ) {
45- crashlyticsReference. setCustomValue ( 42 , forKey: " MeaningOfLife " )
46- crashlyticsReference. setCustomValue ( " Test value " , forKey: " last_UI_action " )
47- let customKeysObject = [
48- " locale " : reachabilityHelper. getLocale ( ) ,
49- " network_connection " : reachabilityHelper. getNetworkStatus ( ) ,
50- ] as [ String : Any ]
51- crashlyticsReference. setCustomKeysAndValues ( customKeysObject)
52- reachabilityHelper. updateAndTrackNetworkStatus ( )
53- Crashlytics . crashlytics ( ) . setUserID ( " 123456789 " )
54- }
46+ func setCustomValues( ) {
47+ crashlyticsReference. setCustomValue ( 42 , forKey: " MeaningOfLife " )
48+ crashlyticsReference. setCustomValue ( " Test value " , forKey: " last_UI_action " )
49+ // Reachability is not compatible with watchOS
50+ #if !os(watchOS)
51+ let customKeysObject = [
52+ " locale " : reachabilityHelper. getLocale ( ) ,
53+ " network_connection " : reachabilityHelper. getNetworkStatus ( ) ,
54+ ] as [ String : Any ]
55+ crashlyticsReference. setCustomKeysAndValues ( customKeysObject)
56+ reachabilityHelper. updateAndTrackNetworkStatus ( )
57+ #endif
58+ Crashlytics . crashlytics ( ) . setUserID ( " 123456789 " )
59+ }
5560
56- init ( ) {
57- FirebaseApp . configure ( )
58- Crashlytics . crashlytics ( ) . log ( " App loaded " )
59- setCustomValues ( )
60- setUserInfo ( )
61- }
61+ init ( ) {
62+ FirebaseApp . configure ( )
63+ Crashlytics . crashlytics ( ) . log ( " App loaded " )
64+ setCustomValues ( )
65+ setUserInfo ( )
66+ }
6267
63- var body : some Scene {
64- WindowGroup {
65- ContentView ( )
66- }
68+ var body : some Scene {
69+ WindowGroup {
70+ ContentView ( )
6771 }
72+ }
6873}
0 commit comments