Skip to content

Commit f34389a

Browse files
authored
Merge pull request #1781 from firebase/nc/remove-reachability
fix: Remove Reachability dependency
2 parents ad7b9e3 + 895afa6 commit f34389a

File tree

5 files changed

+126
-154
lines changed

5 files changed

+126
-154
lines changed

crashlytics/CrashlyticsExample.xcodeproj/project.pbxproj

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
8D00BB732D3B0AED00F6F6DD /* FirebaseCrashlytics in Frameworks */ = {isa = PBXBuildFile; productRef = 8D00BB722D3B0AED00F6F6DD /* FirebaseCrashlytics */; };
1212
8D00BB752D3B0AF400F6F6DD /* FirebaseCrashlytics in Frameworks */ = {isa = PBXBuildFile; productRef = 8D00BB742D3B0AF400F6F6DD /* FirebaseCrashlytics */; };
1313
8D00BB772D3B0AFF00F6F6DD /* FirebaseCrashlytics in Frameworks */ = {isa = PBXBuildFile; productRef = 8D00BB762D3B0AFF00F6F6DD /* FirebaseCrashlytics */; };
14-
8D96F5DE2685440700F1A2B7 /* Reachability in Frameworks */ = {isa = PBXBuildFile; productRef = 8D96F5DD2685440700F1A2B7 /* Reachability */; };
15-
8D96F5E62685442800F1A2B7 /* ReachabililtyHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = C723B78C26853A1700AD34CD /* ReachabililtyHelper.swift */; };
16-
8D96F5EE2685442C00F1A2B7 /* ReachabililtyHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = C723B78C26853A1700AD34CD /* ReachabililtyHelper.swift */; };
14+
8D96F5E62685442800F1A2B7 /* ReachabilityHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = C723B78C26853A1700AD34CD /* ReachabilityHelper.swift */; };
15+
8D96F5EE2685442C00F1A2B7 /* ReachabilityHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = C723B78C26853A1700AD34CD /* ReachabilityHelper.swift */; };
1716
C726B81C26D84D51000991C1 /* UITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C726B81B26D84D51000991C1 /* UITests.swift */; };
1817
C73C89A926845908003E5C2C /* CrashlyticsSwiftUIExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = C73C899726845907003E5C2C /* CrashlyticsSwiftUIExampleApp.swift */; };
1918
C73C89AA26845908003E5C2C /* CrashlyticsSwiftUIExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = C73C899726845907003E5C2C /* CrashlyticsSwiftUIExampleApp.swift */; };
@@ -35,9 +34,8 @@
3534
C74C554A26B377F20043B835 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C74C554926B377F20043B835 /* Preview Assets.xcassets */; };
3635
C77AC00526BB151000BDE919 /* Reachability in Frameworks */ = {isa = PBXBuildFile; productRef = C77AC00426BB151000BDE919 /* Reachability */; };
3736
C77AC00626BB16C200BDE919 /* CrashlyticsSwiftUIExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = C73C899726845907003E5C2C /* CrashlyticsSwiftUIExampleApp.swift */; };
38-
C77AC00726BB16C500BDE919 /* ReachabililtyHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = C723B78C26853A1700AD34CD /* ReachabililtyHelper.swift */; };
37+
C77AC00726BB16C500BDE919 /* ReachabilityHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = C723B78C26853A1700AD34CD /* ReachabilityHelper.swift */; };
3938
C77AC00826BB16CA00BDE919 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C73C899826845907003E5C2C /* ContentView.swift */; };
40-
C77AC00C26BB16E300BDE919 /* Reachability in Frameworks */ = {isa = PBXBuildFile; productRef = C77AC00B26BB16E300BDE919 /* Reachability */; };
4139
C79FD3BA26C728D800FE0261 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = C79FD3B926C728D800FE0261 /* GoogleService-Info.plist */; };
4240
C79FD3BB26C728D800FE0261 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = C79FD3B926C728D800FE0261 /* GoogleService-Info.plist */; };
4341
C79FD3BC26C728D800FE0261 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = C79FD3B926C728D800FE0261 /* GoogleService-Info.plist */; };
@@ -119,7 +117,7 @@
119117
/* End PBXCopyFilesBuildPhase section */
120118

121119
/* Begin PBXFileReference section */
122-
C723B78C26853A1700AD34CD /* ReachabililtyHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReachabililtyHelper.swift; sourceTree = "<group>"; };
120+
C723B78C26853A1700AD34CD /* ReachabilityHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReachabilityHelper.swift; sourceTree = "<group>"; };
123121
C726B81926D84D51000991C1 /* UITests_iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UITests_iOS.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
124122
C726B81B26D84D51000991C1 /* UITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UITests.swift; sourceTree = "<group>"; };
125123
C73C899726845907003E5C2C /* CrashlyticsSwiftUIExampleApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CrashlyticsSwiftUIExampleApp.swift; sourceTree = "<group>"; };
@@ -174,7 +172,6 @@
174172
isa = PBXFrameworksBuildPhase;
175173
buildActionMask = 2147483647;
176174
files = (
177-
C77AC00526BB151000BDE919 /* Reachability in Frameworks */,
178175
8D00BB752D3B0AF400F6F6DD /* FirebaseCrashlytics in Frameworks */,
179176
);
180177
runOnlyForDeploymentPostprocessing = 0;
@@ -264,7 +261,7 @@
264261
isa = PBXGroup;
265262
children = (
266263
C73C899726845907003E5C2C /* CrashlyticsSwiftUIExampleApp.swift */,
267-
C723B78C26853A1700AD34CD /* ReachabililtyHelper.swift */,
264+
C723B78C26853A1700AD34CD /* ReachabilityHelper.swift */,
268265
C73C899826845907003E5C2C /* ContentView.swift */,
269266
C726B81B26D84D51000991C1 /* UITests.swift */,
270267
C73C899926845908003E5C2C /* Assets.xcassets */,
@@ -398,7 +395,6 @@
398395
);
399396
name = "CrashlyticsExample (macOS)";
400397
packageProductDependencies = (
401-
C77AC00426BB151000BDE919 /* Reachability */,
402398
8D00BB742D3B0AF400F6F6DD /* FirebaseCrashlytics */,
403399
);
404400
productName = "CrashlyticsSwiftUIExample (macOS)";
@@ -574,7 +570,6 @@
574570
);
575571
mainGroup = 5F5A53431ADE670C00F81DF0;
576572
packageReferences = (
577-
8D96F5DC2685440700F1A2B7 /* XCRemoteSwiftPackageReference "Reachability.swift" */,
578573
8D00BB6E2D3B0ACF00F6F6DD /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */,
579574
);
580575
productRefGroup = 5F5A534D1ADE670C00F81DF0 /* Products */;
@@ -708,7 +703,7 @@
708703
isa = PBXSourcesBuildPhase;
709704
buildActionMask = 2147483647;
710705
files = (
711-
8D96F5E62685442800F1A2B7 /* ReachabililtyHelper.swift in Sources */,
706+
8D96F5E62685442800F1A2B7 /* ReachabilityHelper.swift in Sources */,
712707
C73C89AB26845908003E5C2C /* ContentView.swift in Sources */,
713708
C73C89A926845908003E5C2C /* CrashlyticsSwiftUIExampleApp.swift in Sources */,
714709
);
@@ -718,7 +713,7 @@
718713
isa = PBXSourcesBuildPhase;
719714
buildActionMask = 2147483647;
720715
files = (
721-
8D96F5EE2685442C00F1A2B7 /* ReachabililtyHelper.swift in Sources */,
716+
8D96F5EE2685442C00F1A2B7 /* ReachabilityHelper.swift in Sources */,
722717
C73C89AC26845908003E5C2C /* ContentView.swift in Sources */,
723718
C73C89AA26845908003E5C2C /* CrashlyticsSwiftUIExampleApp.swift in Sources */,
724719
);
@@ -733,6 +728,7 @@
733728
C745941226BDDD6200153AE3 /* ComplicationController.swift in Sources */,
734729
C745942726BDDDEF00153AE3 /* CrashlyticsSwiftUIExampleApp.swift in Sources */,
735730
C745941026BDDD6200153AE3 /* NotificationView.swift in Sources */,
731+
8D96F5E62685442800F1A2B7 /* ReachabilityHelper.swift in Sources */,
736732
);
737733
runOnlyForDeploymentPostprocessing = 0;
738734
};
@@ -741,7 +737,7 @@
741737
buildActionMask = 2147483647;
742738
files = (
743739
C77AC00626BB16C200BDE919 /* CrashlyticsSwiftUIExampleApp.swift in Sources */,
744-
C77AC00726BB16C500BDE919 /* ReachabililtyHelper.swift in Sources */,
740+
C77AC00726BB16C500BDE919 /* ReachabilityHelper.swift in Sources */,
745741
C77AC00826BB16CA00BDE919 /* ContentView.swift in Sources */,
746742
);
747743
runOnlyForDeploymentPostprocessing = 0;
@@ -1636,14 +1632,6 @@
16361632
minimumVersion = 11.7.0;
16371633
};
16381634
};
1639-
8D96F5DC2685440700F1A2B7 /* XCRemoteSwiftPackageReference "Reachability.swift" */ = {
1640-
isa = XCRemoteSwiftPackageReference;
1641-
repositoryURL = "https://github.com/ashleymills/Reachability.swift.git";
1642-
requirement = {
1643-
kind = upToNextMajorVersion;
1644-
minimumVersion = 5.1.0;
1645-
};
1646-
};
16471635
/* End XCRemoteSwiftPackageReference section */
16481636

16491637
/* Begin XCSwiftPackageProductDependency section */
@@ -1667,21 +1655,6 @@
16671655
package = 8D00BB6E2D3B0ACF00F6F6DD /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */;
16681656
productName = FirebaseCrashlytics;
16691657
};
1670-
8D96F5DD2685440700F1A2B7 /* Reachability */ = {
1671-
isa = XCSwiftPackageProductDependency;
1672-
package = 8D96F5DC2685440700F1A2B7 /* XCRemoteSwiftPackageReference "Reachability.swift" */;
1673-
productName = Reachability;
1674-
};
1675-
C77AC00426BB151000BDE919 /* Reachability */ = {
1676-
isa = XCSwiftPackageProductDependency;
1677-
package = 8D96F5DC2685440700F1A2B7 /* XCRemoteSwiftPackageReference "Reachability.swift" */;
1678-
productName = Reachability;
1679-
};
1680-
C77AC00B26BB16E300BDE919 /* Reachability */ = {
1681-
isa = XCSwiftPackageProductDependency;
1682-
package = 8D96F5DC2685440700F1A2B7 /* XCRemoteSwiftPackageReference "Reachability.swift" */;
1683-
productName = Reachability;
1684-
};
16851658
/* End XCSwiftPackageProductDependency section */
16861659
};
16871660
rootObject = 5F5A53441ADE670C00F81DF0 /* Project object */;

crashlytics/OUTLINE.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,14 @@ operating system, time of crash), the crash report contains custom keys and logs
2222
network status) which can help developers to debug the crash as well as illustrate how to add custom
2323
data to their own crashes.
2424

25-
### Reachability
25+
### Network Status
2626
There are many reasons behind a crash, and developers are challenged to understand the root cause
2727
behind the crash in order to apply the proper fix. Thus, receiving different types of information
28-
from the crash can help developers to understand the crash. Reachability gives information about a
28+
from the crash can help developers to understand the crash. Network status gives information about a
2929
device’s network configuration settings.
30-
[Reachability.swift](https://github.com/ashleymills/Reachability.swift) uses the [System
31-
Configuration](https://developer.apple.com/documentation/systemconfiguration) framework to monitor
32-
the network state of a device. It is a replacement for [Apple's
33-
Reachability](https://developer.apple.com/library/archive/samplecode/Reachability/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007324)
34-
(written in Objective-C) re-written in Swift with closures.
30+
This quickstart uses Apple's [Network](https://developer.apple.com/documentation/network)
31+
framework to monitor the network state of a device. Specifically, it uses `NWPathMonitor` to get
32+
network status changes.
3533

3634
### Cross Platform
3735
This Quickstart supports all Apple platforms including iOS, macOS, tvOS and watchOS. The SwiftUI

crashlytics/Shared/CrashlyticsSwiftUIExampleApp.swift

Lines changed: 41 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,60 +14,55 @@
1414
// limitations under the License.
1515
//
1616

17-
import SwiftUI
1817
import FirebaseCore
1918
import FirebaseCrashlytics
19+
import SwiftUI
2020

2121
@main
2222
struct CrashlyticsSwiftUIExampleApp: App {
23-
private var crashlyticsReference = Crashlytics.crashlytics()
24-
#if !os(watchOS)
25-
let reachabilityHelper = ReachabililtyHelper()
26-
#endif
23+
private var crashlyticsReference = Crashlytics.crashlytics()
24+
let reachabilityHelper = ReachabilityHelper()
2725

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-
}
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+
}
4543

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-
}
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+
}
6055

61-
init() {
62-
FirebaseApp.configure()
63-
Crashlytics.crashlytics().log("App loaded")
64-
setCustomValues()
65-
setUserInfo()
66-
}
56+
init() {
57+
FirebaseApp.configure()
58+
Crashlytics.crashlytics().log("App loaded")
59+
setCustomValues()
60+
setUserInfo()
61+
}
6762

68-
var body: some Scene {
69-
WindowGroup {
70-
ContentView()
63+
var body: some Scene {
64+
WindowGroup {
65+
ContentView()
66+
}
7167
}
72-
}
7368
}

crashlytics/Shared/ReachabililtyHelper.swift

Lines changed: 0 additions & 65 deletions
This file was deleted.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//
2+
// Copyright 2021 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+
17+
import FirebaseCrashlytics
18+
import Foundation
19+
import Network
20+
21+
class ReachabilityHelper: NSObject {
22+
private let monitor: NWPathMonitor
23+
24+
override init() {
25+
monitor = NWPathMonitor()
26+
super.init()
27+
}
28+
29+
/**
30+
* Retrieve the locale information for the app.
31+
*/
32+
func getLocale() -> String {
33+
return Locale.preferredLanguages[0]
34+
}
35+
36+
/**
37+
* Retrieve the network status for the app.
38+
*/
39+
func getNetworkStatus() -> String {
40+
return networkStatus(from: monitor.currentPath)
41+
}
42+
43+
private func networkStatus(from path: NWPath) -> String {
44+
if path.status == .satisfied {
45+
if path.usesInterfaceType(.wifi) {
46+
return "wifi"
47+
} else if path.usesInterfaceType(.cellular) {
48+
return "cellular"
49+
} else if path.usesInterfaceType(.wiredEthernet) {
50+
return "wired"
51+
} else {
52+
return "other"
53+
}
54+
} else {
55+
return "unavailable"
56+
}
57+
}
58+
59+
/**
60+
* Add a hook to update network status going forward.
61+
*/
62+
func updateAndTrackNetworkStatus() {
63+
monitor.pathUpdateHandler = { [weak self] path in
64+
guard let self = self else { return }
65+
let status = self.networkStatus(from: path)
66+
Crashlytics.crashlytics().setCustomValue(status, forKey: "network_connection")
67+
}
68+
let queue = DispatchQueue(label: "NetworkMonitor")
69+
monitor.start(queue: queue)
70+
}
71+
}

0 commit comments

Comments
 (0)