Moin Shirazi Moin Shirazi - 1 year ago 64
iOS Question

Invalidate NSTimer after VC is changed

I am having a

in my VC and its working fine its sending location of user and i cant invalidate it on
as i need to send in background also.

myTimer=[NSTimer scheduledTimerWithTimeInterval:2.0 target: self
selector: @selector(sendDataToSocket) userInfo: nil repeats: YES];

But the issue is when i instantiate same VC again it start the
again and 2 timers are working. so how can i stop the previous one or any other solution

Any help will be appreciated

Answer Source

You can use the singleton class or simple use the appDelegate class to just declare the myTimer object in appDelegate and use it in your viewController.

This will have a single object of timer and you dont need to create multiple objects and your ultimate objective will be resolved. Hope this Helps!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download