0
votes

I'm displaying a local notification every day at 9AM with exchange rates. But if value of (let's say euro for example) is the same as yesterday then it should't fire. I'm downloading data from my server using XML. So my question is it possible to parse XML data(every day at 9AM before displaying notification) while app is not running (killed with task manager), since displaying notifications is (even when app is killed totally).

This is how I fire my notification:

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];
2

2 Answers

0
votes

If you can send APNS push notifications to your app you can wake it from background and have it process your xml (when exchange rates change for example) and schedule the local notification.

0
votes

You have to use the silent push notification. It will launch you application in background without knowing the user and then you can download the xml and do the comparison. if it is same fire the local notification which will shown to the user and then user can proceed further.

NOTE: Apple gives max 30 seconds to perform you task in background