Sorum en yalın haliyle "internet baglantisi olmadiginda uyari verdik. ardindan kullanici wifi yada 3g baglantisini acti ve internete baglandi. Sonrasinda uygulama internetin aktif oldugu anlayip yeniden islem yapmaya baslayacak? " yukaridaki kod blogu benim kullandigim reachability sinifinda hatalar verdi. benim kulladigim reachability sinifi asagidaki kadar sorun reachability'de de olabilirmi acaba?
import Foundation
import SystemConfiguration
public class Reachability {
class func isConnectedToNetwork() -> Bool {
var zeroAddress = sockaddr_in(sin_len: 0, sin_family: 0, sin_port: 0, sin_addr: in_addr(s_addr: 0), sin_zero: (0, 0, 0, 0, 0, 0, 0, 0))
zeroAddress.sin_len = UInt8(sizeofValue(zeroAddress))
zeroAddress.sin_family = sa_family_t(AF_INET)
let defaultRouteReachability = withUnsafePointer(&zeroAddress) {
SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, UnsafePointer($0))
}
var flags: SCNetworkReachabilityFlags = SCNetworkReachabilityFlags(rawValue: 0)
if SCNetworkReachabilityGetFlags(defaultRouteReachability!, &flags) == false {
return false
}
let isReachable = flags == .Reachable
let needsConnection = flags == .ConnectionRequired
return isReachable && !needsConnection
}
}