1

I have enable my mobile data (3G/4G) but there is no data left in my Mobile Network.

Is it possible to know above condition in swift.

I have checked below code but its giving me wrong information. Below condition is only satisfied when off the mobile data. My requirement is mobile data is ON and no internet avialable

    let reachability = Reachability(hostName: "https://www.google.com")
    if reachability.currentReachabilityStatus() == NotReachable {

    }
Sree
  • 113
  • 11

1 Answers1

2

Find the solution which worked for me

func isConnectedToNetwork()->Bool {
    var Status:Bool = false
    let url = NSURL(string: "http://google.com/")
    let request = NSMutableURLRequest(URL: url!)
    request.HTTPMethod = "HEAD"
    request.cachePolicy = NSURLRequestCachePolicy.ReloadIgnoringLocalAndRemoteCacheData
    request.timeoutInterval = 10.0
    var response: NSURLResponse?
    _ = try? NSURLConnection.sendSynchronousRequest(request, returningResponse: &response) as NSData?
    if let httpResponse = response as? NSHTTPURLResponse {
        if httpResponse.statusCode == 200 {
            Status = true
        }
    }
    return Status
}
Sree
  • 113
  • 11