如何一次在本地通知中将日期数组设置为fireDate [英] how to set array of date to fireDate in local notification at a time

查看:56
本文介绍了如何一次在本地通知中将日期数组设置为fireDate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,在我的应用中,我在不同的时间启动了两个以上的计时器.在特定的时间间隔后,我希望触发通知.当应用程序在前台但不在后台时,它工作正常.我该如何解决?

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?

请帮助.谢谢!

推荐答案

您需要执行以下操作...

You need to do following...

您需要打开后台模式.

在AppDelegate中,添加此代码以在后台运行应用程序

In AppDelegate, Add this code to run app in background

创建属性

@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.

这篇关于如何一次在本地通知中将日期数组设置为fireDate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆