I am New in iOS, In my Project ,i am using NSTimer with Navigation Controller. I used two Classes in my project, Class 1 is ViewController and 2nd Class is PlayTheme. ViewController and PlayTheme Classes are connected with segue. In PlayTheme Class i used NSTimer and "FiredTimer method" call for Every 10 miliseconds. Source Code of PlayTheme Class is: Below Method For NSTimer Start
- (IBAction)startTimerMethod:(id)sender
{
UIBackgroundTaskIdentifier bgTask =0;
UIApplication *app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
}];
timer = [NSTimer
scheduledTimerWithTimeInterval:0.01
target:self
selector:@selector(timerFired:)
userInfo:nil
repeats:YES];
}
And Below Method is Stop timer
- (IBAction)stopTimerMethod:(id)sender
{
if([timer isValid])
{
[timer invalidate];
timer=Nil;
}
}
Both Methods are Working ,but When i follows the Below steps the timer Does Not Stop :
- I'm in PlayTheme Class and StartTime
- Go Back to ViewController
- Come Back To PlayTheme Class
- and StopTimer Method Call,Method Call But but Does Not Stop Timer
Give Me suggestion for solving my problem and also tell me how NSTimer work in BackGround to play sound for a specific time using NSTimer ?
Thank You in Advanced.