问题
Actually in my app I'm starting more than two timers at different times. After certain time intervals I want notifications to fire. It's working fine when the app is on foreground but not in the background. How can I solve this?
Please help. Thanks!
回答1:
You need to do following...
You need to turn on background mode.
In AppDelegate, Add this code to run app in background
Create a property
@property (nonatomic, assign) UIBackgroundTaskIdentifier backgroundTask;
and then do following...
- (void)applicationDidEnterBackground:(UIApplication *)application {
self.backgroundTask = [application beginBackgroundTaskWithExpirationHandler:^{
DLOG(@"End of tolerate time. Application should be suspended now if we do not ask more 'tolerance'");
}];
if (self.backgroundTask == UIBackgroundTaskInvalid) {
DLOG(@"This application does not support background mode");
} else {
//if application supports background mode, we'll see this log.
DLOG(@"Application will continue to run in background");
}
}
I hope it will help you.
回答2:
you can handle with both timer into this appdelgate method
- (void)applicationDidEnterBackground:(UIApplication *)application {
}
when app going to background that time this method is called and your code still execute into this method, Hope this will help you.
Note : first enable background mode into Project Target -> Availability Tab -> Background Modes -> ON
来源:https://stackoverflow.com/questions/42647210/how-to-set-array-of-date-to-firedate-in-local-notification-at-a-time