Skip to content

Commit

Permalink
Fix for connection check without starting notifier
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleymills committed Aug 30, 2018
1 parent 6ca36a9 commit 89d8ac7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion ReachabilityAppleTVSample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>4.0</string>
<string>4.2.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
2 changes: 1 addition & 1 deletion ReachabilityMacSample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>4.0</string>
<string>4.2.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
2 changes: 1 addition & 1 deletion ReachabilitySample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>4.0</string>
<string>4.2.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
2 changes: 1 addition & 1 deletion ReachabilitySwift.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'ReachabilitySwift'
s.version = '4.2.0'
s.version = '4.2.1'
s.module_name = 'Reachability'
s.homepage = 'https://github.com/ashleymills/Reachability.swift'
s.authors = {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>4.1.0</string>
<string>4.2.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
26 changes: 17 additions & 9 deletions Sources/Reachability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public class Reachability {
}

public var connection: Connection {
if flags == nil {
try? setReachabilityFlags()
}

switch flags?.connection {
case .none?, nil: return .none
case .cellular?: return allowsCellularConnection ? .cellular : .none
Expand Down Expand Up @@ -171,15 +175,7 @@ public extension Reachability {
}

// Perform an initial check
try reachabilitySerialQueue.sync { [unowned self] in
var flags = SCNetworkReachabilityFlags()
if !SCNetworkReachabilityGetFlags(self.reachabilityRef, &flags) {
self.stopNotifier()
throw ReachabilityError.UnableToGetInitialFlags
}

self.flags = flags
}
try setReachabilityFlags()

notifierRunning = true
}
Expand Down Expand Up @@ -226,6 +222,18 @@ public extension Reachability {

fileprivate extension Reachability {

func setReachabilityFlags() throws {
try reachabilitySerialQueue.sync { [unowned self] in
var flags = SCNetworkReachabilityFlags()
if !SCNetworkReachabilityGetFlags(self.reachabilityRef, &flags) {
self.stopNotifier()
throw ReachabilityError.UnableToGetInitialFlags
}

self.flags = flags
}
}

func reachabilityChanged() {
let block = connection != .none ? whenReachable : whenUnreachable

Expand Down

0 comments on commit 89d8ac7

Please sign in to comment.