我每天在9点以汇率显示本地通知。但是,如果(比如说欧元)的价值与昨天一样,那么它不应该开火。我正在使用XML从我的服务器下载数据。所以我的问题是可能解析XML数据(每天早上9点才显示通知),而应用程序没有运行(杀死与任务管理器),因为显示通知是(即使当应用程序完全被杀害)。iOS本地通知自定义数据
这是我火我的通知:
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];
是的,我知道,但我试图做到这一点没有APNS,仅有局部。 – user3251 2015-02-05 22:38:18
我不相信你可以在本地通知中执行任务。你不能为OS做“安排工作”。所以我很害怕你想达到的目标是不可能的。 – tmpz 2015-02-05 22:43:47