0

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

Mike Abdullah
  • 14,933
  • 2
  • 50
  • 75
zhuber
  • 5,364
  • 3
  • 30
  • 63

1 Answers1

1

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.

felix
  • 11,304
  • 13
  • 69
  • 95
  • Tnx. Server return bool - true, false, and I check that with [[jsonArray objectForKey:@"status"] boolValue] == true (or false), but how can I check if nothing is returned ? If I put [jsonArray objectForKey:@"status"] == nil it still return alert for as status is false. – zhuber May 20 '13 at 15:56
  • Got it. Just checked if jsonArray is NULL. Tnx anyway on suggestion. – zhuber May 20 '13 at 16:00
  • Do I set timer as property or instance variable ? And what reference should I use if used as property ? tnx – zhuber May 20 '13 at 16:05