Search code examples
iosswift3ios10uilocalnotification

how to set array of date to fireDate in local notification at a time


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!


Solution

  • You need to do following...

    enter image description here

    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.