I am testing out a NSTimer with selector in sceneDidEnterBackground, but the selector does not run when I press the home button once. I am trying to run a timer when the home button is pressed once. Does anyone know what is wrong? This is my code in SceneDelegate.m
- (void)sceneDidEnterBackground:(UIScene *)scene {
NSTimer *t = [NSTimer scheduledTimerWithTimeInterval: 2.0
target: self
selector:@selector(test)
userInfo: nil repeats:NO];
// NSLog(@"test"); //it prints out "test" here
[(AppDelegate *)UIApplication.sharedApplication.delegate saveContext];
}
- (void) test{
NSLog(@"test");
}