【发布时间】:2015-02-05 22:21:33
【问题描述】:
我每天上午 9 点显示本地通知,其中包含汇率。但是,如果(例如欧元)的价值与昨天相同,那么它不应该触发。我正在使用 XML 从我的服务器下载数据。所以我的问题是可以在应用程序未运行(被任务管理器杀死)时解析 XML 数据(每天上午 9 点在显示通知之前),因为显示通知是(即使应用程序被完全杀死)。
这就是我触发通知的方式:
NSDate *now = [NSDate date];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:now];
[components setHour:9];
// Gives us today's date but at 9am
NSDate *next9am = [calendar dateFromComponents:components];
if ([next9am timeIntervalSinceNow] < 0) {
// If today's 9am already occurred, add 24hours to get to tomorrow's
next9am = [next9am dateByAddingTimeInterval:60*60*24];
}
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = next9am;
notification.alertBody = @"Euro value: <PARSED VALUE HERE>";
// Set a repeat interval to daily
notification.repeatInterval = NSDayCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
【问题讨论】:
标签: ios objective-c xml-parsing uilocalnotification