iOS本地通知自定义数据
问题描述:
我每天在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推送通知到你的应用程序,你可以从后台唤醒它,并把它处理XML(当汇率变化为例)和安排本地通知。
答
您必须使用静默推送通知。它会在不知道用户的情况下在后台启动应用程序,然后可以下载xml并进行比较。如果它是同一火灾,将向用户显示的本地通知,然后用户可以继续进行。
注:苹果公司给出了最大值30秒,在后台执行任务,你
是的,我知道,但我试图做到这一点没有APNS,仅有局部。 – user3251 2015-02-05 22:38:18
我不相信你可以在本地通知中执行任务。你不能为OS做“安排工作”。所以我很害怕你想达到的目标是不可能的。 – tmpz 2015-02-05 22:43:47