Skip to content

Commit 4bd93a6

Browse files
committed
fix: Remove Reachability dependency
The main issue is that the Reachability package does not get built as a non-Firebase SDK by the release tooling. It's possible to work around but I was trying to avoid more special casing.
1 parent ad7b9e3 commit 4bd93a6

File tree

4 files changed

+45
-71
lines changed

4 files changed

+45
-71
lines changed

crashlytics/CrashlyticsExample.xcodeproj/project.pbxproj

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
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 */; };
1514
8D96F5E62685442800F1A2B7 /* ReachabililtyHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = C723B78C26853A1700AD34CD /* ReachabililtyHelper.swift */; };
1615
8D96F5EE2685442C00F1A2B7 /* ReachabililtyHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = C723B78C26853A1700AD34CD /* ReachabililtyHelper.swift */; };
1716
C726B81C26D84D51000991C1 /* UITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C726B81B26D84D51000991C1 /* UITests.swift */; };
@@ -37,7 +36,6 @@
3736
C77AC00626BB16C200BDE919 /* CrashlyticsSwiftUIExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = C73C899726845907003E5C2C /* CrashlyticsSwiftUIExampleApp.swift */; };
3837
C77AC00726BB16C500BDE919 /* ReachabililtyHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = C723B78C26853A1700AD34CD /* ReachabililtyHelper.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 */; };
@@ -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;
@@ -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 */;
@@ -1636,14 +1631,6 @@
16361631
minimumVersion = 11.7.0;
16371632
};
16381633
};
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-
};
16471634
/* End XCRemoteSwiftPackageReference section */
16481635

16491636
/* Begin XCSwiftPackageProductDependency section */
@@ -1667,21 +1654,6 @@
16671654
package = 8D00BB6E2D3B0ACF00F6F6DD /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */;
16681655
productName = FirebaseCrashlytics;
16691656
};
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-
};
16851657
/* End XCSwiftPackageProductDependency section */
16861658
};
16871659
rootObject = 5F5A53441ADE670C00F81DF0 /* Project object */;

crashlytics/OUTLINE.md

Lines changed: 9 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
@@ -70,5 +68,9 @@ Below are the screenshots for selected build schemes:
7068
### CrashlyticsExample (tvOS)
7169
<br><img src="./Design/Screenshots/crashlytics_tvos.png" alt="tvOS Screenshot" width=400>
7270

71+
### CrashlyticsExample (watchOS)
72+
<br><img src="./Design/Screenshots/crashlytics_watchos.png" alt="watchOS Screenshot" width=200>mple (tvOS)
73+
<br><img src="./Design/Screenshots/crashlytics_tvos.png" alt="tvOS Screenshot" width=400>
74+
7375
### CrashlyticsExample (watchOS)
7476
<br><img src="./Design/Screenshots/crashlytics_watchos.png" alt="watchOS Screenshot" width=200>

crashlytics/Shared/CrashlyticsSwiftUIExampleApp.swift

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ import FirebaseCrashlytics
2121
@main
2222
struct CrashlyticsSwiftUIExampleApp: App {
2323
private var crashlyticsReference = Crashlytics.crashlytics()
24-
#if !os(watchOS)
25-
let reachabilityHelper = ReachabililtyHelper()
26-
#endif
24+
let reachabilityHelper = ReachabililtyHelper()
2725

2826
func setUserInfo() {
2927
let userInfo = [
@@ -46,15 +44,12 @@ struct CrashlyticsSwiftUIExampleApp: App {
4644
func setCustomValues() {
4745
crashlyticsReference.setCustomValue(42, forKey: "MeaningOfLife")
4846
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
47+
let customKeysObject = [
48+
"locale": reachabilityHelper.getLocale(),
49+
"network_connection": reachabilityHelper.getNetworkStatus(),
50+
] as [String: Any]
51+
crashlyticsReference.setCustomKeysAndValues(customKeysObject)
52+
reachabilityHelper.updateAndTrackNetworkStatus()
5853
Crashlytics.crashlytics().setUserID("123456789")
5954
}
6055

crashlytics/Shared/ReachabililtyHelper.swift

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,16 @@
1616

1717
import Foundation
1818
import FirebaseCrashlytics
19-
import Reachability
19+
import Network
2020

2121
class ReachabililtyHelper: NSObject {
22+
private let monitor: NWPathMonitor
23+
24+
override init() {
25+
monitor = NWPathMonitor()
26+
super.init()
27+
}
28+
2229
/**
2330
* Retrieve the locale information for the app.
2431
*/
@@ -30,15 +37,21 @@ class ReachabililtyHelper: NSObject {
3037
* Retrieve the network status for the app.
3138
*/
3239
func getNetworkStatus() -> String {
33-
guard let reachability = try? Reachability() else {
34-
return "unknown"
35-
}
36-
switch reachability.connection {
37-
case .wifi:
38-
return "wifi"
39-
case .cellular:
40-
return "cellular"
41-
case .unavailable:
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 {
4255
return "unavailable"
4356
}
4457
}
@@ -47,19 +60,11 @@ class ReachabililtyHelper: NSObject {
4760
* Add a hook to update network status going forward.
4861
*/
4962
func updateAndTrackNetworkStatus() {
50-
NotificationCenter.default.addObserver(self,
51-
selector: #selector(reachabilityChanged(note:)),
52-
name: .reachabilityChanged,
53-
object: nil)
54-
do {
55-
let reachability = try Reachability()
56-
try reachability.startNotifier()
57-
} catch {
58-
print("Could not start reachability notifier: \(error)")
63+
monitor.pathUpdateHandler = { path in
64+
let status = self.networkStatus(from: path)
65+
Crashlytics.crashlytics().setCustomValue(status, forKey: "network_connection")
5966
}
67+
let queue = DispatchQueue(label: "NetworkMonitor")
68+
monitor.start(queue: queue)
6069
}
61-
62-
@objc func reachabilityChanged(note: Notification) {
63-
Crashlytics.crashlytics().setCustomValue(getNetworkStatus(), forKey: "network_connection")
64-
}
65-
}
70+
}

0 commit comments

Comments
 (0)