Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Reach {
- private var reachability: SCNetworkReachability!
- func connectionStatus() -> ReachabilityStatus {
- // ...
- return ReachabilityStatus(reachabilityFlags: flags)
- }
- func monitorReachabilityChanges() {
- let host = "google.com"
- var context = SCNetworkReachabilityContext(version: 0, info: nil, retain: nil, release: nil, copyDescription: nil)
- reachability = SCNetworkReachabilityCreateWithName(nil, host)!
- SCNetworkReachabilitySetCallback(reachability, callback, &context)
- SCNetworkReachabilityScheduleWithRunLoop(reachability, CFRunLoopGetMain(), kCFRunLoopCommonModes)
- }
- func stopMonitoringReachabilityChanges() {
- SCNetworkReachabilityUnscheduleFromRunLoop(reachability, CFRunLoopGetMain(), kCFRunLoopCommonModes)
- }
- }
- func callback(reachability: SCNetworkReachability, flags: SCNetworkReachabilityFlags, pointer: UnsafeMutablePointer<Void>) {
- let obj = Unmanaged<Reach>.fromOpaque(COpaquePointer(pointer)).takeUnretainedValue() // attempt to create an Unmanaged instance from a null pointer
- let status = ReachabilityStatus(reachabilityFlags: flags)
- NSNotificationCenter.defaultCenter().postNotificationName(ReachabilityStatusChangedNotification, object: nil, userInfo: ["Status": status.description])
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement