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

不想你离开。 提交于 2020-01-06 02:18:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!