E
E
Empty User2015-03-31 13:39:01
Mobile development
Empty User, 2015-03-31 13:39:01

Should I use NSTimer?

Good afternoon! I am writing a mobile application, and there you need to consider whether there is a network connection. If there is no connection, then the buttons disappear. So I solved this problem with the help of NSTimer and the Reachability class. Some code looks like this:
self.timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("checkConnection"), userInfo: nil, repeats: true)
...
func checkConnection() {
if Reachability.isConnectedToNetwork() != true{
//Disable buttons here...
}
}
Am I doing the right thing? Will the timer load the system? How do you check your internet connection?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
one pavel, 2015-03-31
@dimash07

Reachability can send notifications when the network disappears or appears, google
search gives great examples:
b2cloud.com.au/tutorial/checking-if-an-ios-app-is-...
tympanus.net/codrops/2009/09/ 14/checking-network-r...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question