Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

func isConnectedToNetwork #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Reach-swift2.0/Reach.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ public class Reach {
SCNetworkReachabilityScheduleWithRunLoop(reachability, CFRunLoopGetMain(), kCFRunLoopCommonModes)
}

func isConnectedToNetwork() -> Bool {
Reach().monitorReachabilityChanges()
let status = Reach().connectionStatus()
switch status {
case .Unknown, .Offline:
return false
case .Online(.WWAN):
return true
case .Online(.WiFi):
return true
}
}

extension ReachabilityStatus {
Expand All @@ -110,4 +121,4 @@ extension ReachabilityStatus {
self = .Offline
}
}
}
}