Frage

I want to download some information from url every 20 seconds and update view based on that info (2-3 labels change text values). I'm using AFNetworking for making request operations in my app.

Should I use NSTimer and make it call method with AFNetworking request every 20 seconds ? Or is there some better way to implement this ?

Thanks

War es hilfreich?

Lösung

You can use an NSTimer. There is a repeats parameters in the NSTimer scheduleWithTimeInterval to do repeating request.

Instead you can also define a method you can call every 20 seconds and in that method you can decide whether to make the request based on some logic(like a boolean) whether the previous request was successful or not. This can be useful, if there is a server problem and you continue requesting the server unnecessarily.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top