2015-02-05 109 views
0

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

回答

0

如果你給APNS推送通知到你的應用程序,你可以從後臺喚醒它,並把它處理XML(當匯率變化爲例)和安排本地通知。

+0

是的,我知道,但我試圖做到這一點沒有APNS,僅有局部。 – user3251 2015-02-05 22:38:18

+0

我不相信你可以在本地通知中執行任務。你不能爲OS做「安排工作」。所以我很害怕你想達到的目標是不可能的。 – tmpz 2015-02-05 22:43:47

0

您必須使用靜默推送通知。它會在不知道用戶的情況下在後臺啓動應用程序,然後可以下載xml並進行比較。如果它是同一火災,將向用戶顯示的本地通知,然後用戶可以繼續進行。

注:蘋果公司給出了最大值30秒,在後臺執行任務,你