I'm trying to check at the launch of the app whether the internet is connected or not. When I switch of my Wifi off and check the work around the app the app is still trying to connect to the internet for 10 seconds. If user is not connected to the internet then I should display an alert that please connect to the internet.
I'm not using localDataStore
.
In my opinion I have to add an internet check statement in queryForTable
.
func baseQuery() -> PFQuery {
let query = PFQuery(className: "homeClass") // Replace with the class name for the Parse data you're interested in.
// Just like with a regular PFQuery you can filter and sort.
query.orderByAscending("SNo")
return query
}
override func queryForTable() -> PFQuery {
if Reachability.isConnectedToNetwork() == true {
print("Internet connection OK")
tableView.reloadData()
self.baseQuery()
} else {
print("Internet connection FAILED")
let alert = UIAlertView(title: "No Internet Connection", message: "Make sure your device is connected to the internet.", delegate: nil, cancelButtonTitle: "OK")
alert.show()
let destinationVC:MainViewController = self.storyboard?.instantiateViewControllerWithIdentifier("NewView") as! MainViewController
navigationController?.pushViewController(destinationVC , animated: true)
}
}
Update
func baseQuery() -> PFQuery {
let query = PFQuery(className: "homeClass")
if Reachability.isConnectedToNetwork() != true {
print("Internet connection FAILED")
} else {
print("Internet connection OK")
query.orderByAscending("SNo")
return query
}
return PFQuery()
}
override func queryForTable() -> PFQuery {
return self.baseQuery()
}
I'm trying this code and still it is trying to fetch data from the internet.