深度win10- 绿色安全免费的win10系统下载站
自助下单地址(拼多多砍价,ks/qq/dy赞等业务):点我进入
问题描述
我的应用程序不断以信息亭模式运行.在特定时间ios是如何使用运行时的,每24小时一次一次ios是如何使用运行时的,我需要将一些数据从核心数据同步到Web服务.
我知道如何进行同步件,但我不知道如何安排应用程序在每天特定时间进行同步调用,例如在上午02:45.
当应用程序不断运行时,可以做类似的事情吗?
推荐答案
使用本地通知.这是一个教程: http:http: icodeblog.com/2010/07/29/iphone-programming-tutorial-local-notifications/
希望这可以帮助您开始...
也是如此:
本地通知
背景任务
其他推荐答案
由于@lakesh的提示,弄清楚了这一点.在此情况下发布解决方案,因为我发现NSNOTIFIENCE示例一开始很难理解.
在我的主视图控制器中,我添加了以下方法:
- (void)scheduleNotification { [[UIApplication sharedApplication] cancelAllLocalNotifications]; UILocalNotification *notif = [[UILocalNotification alloc] init]; NSCalendar *calendar = [NSCalendar currentCalendar]; NSDateComponents *components = [[NSDateComponents alloc] init]; components = [[NSCalendar currentCalendar] components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:[NSDate date]]; NSInteger day = [components day]; NSInteger month = [components month]; NSInteger year = [components year]; [components setDay: day]; [components setMonth: month]; [components setYear: year]; [components setHour: 02]; [components setMinute: 45]; [components setSecond: 0]; [calendar setTimeZone: [NSTimeZone systemTimeZone]]; NSDate *dateToFire = [calendar dateFromComponents:components]; notif.fireDate = dateToFire; notif.timeZone = [NSTimeZone systemTimeZone]; notif.repeatInterval = NSDayCalendarUnit; [[UIApplication sharedApplication] scheduleLocalNotification:notif]; }
这设定了一个射击日期,以在今天上午02:45通知今天,每天递归.
在我的视图控制器中的ViewDidload中,我调用上述方法:
[self scheduleNotification];
在AppDelegate中,我执行以下操作:
- (void)application:(UIApplication *)application didReceiveLocalNotification: (UILocalNotification *)notification { application.applicationIconBadgeNumber = 0; //call your method that you want to do something in your app }
其他推荐答案
一个简单的解决方案只是设置NSTimer每分钟(例如或每秒)检查当前日期.如果当前日期更大,则需要启动方法并更新所需的日期.
更多精彩:寻侠英雄传www.xiame.com2022-03-03 /
系统之家WINDOWS 10 X64完美专业版 2022.03
2022-03-03 /
2022-02-28 /
2022-02-28 /
2022-02-23 /
2022-02-23 /
2022-02-23 /
2022-02-23 /
2022-02-17 /