我每天在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