Muhammad Umar
Muhammad Umar

Reputation: 11782

Adding a local notification once a month iPhone

I am using following code

UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = fireDate;
localNotification.timeZone = [NSTimeZone defaultTimeZone];

localNotification.alertBody = @"Have you seen your Chiropractic this Month?";
localNotification.alertAction = @"Continue";
localNotification.repeatInterval = NSMonthCalendarUnit;

localNotification.applicationIconBadgeNumber = 0;

// Schedule it with the app
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
[localNotification release];

How can i set "fireDate" so that this notification runs only on lets say 5th of every month. Secondly this code is in appDelegate.h. How will i set it so that it launches only one notification each month

Upvotes: 0

Views: 268

Answers (1)

Paul.s
Paul.s

Reputation: 38728

I'm going to guess that the question is actually how do I create a date object to start from

You could start with something like this

NSCalendar *calender = [NSCalendar currentCalendar];
calender.timeZone = [NSTimeZone timeZoneWithName:@"GMT"];

NSDateComponents *components = [calender components:NSMonthCalendarUnit | NSYearCalendarUnit fromDate:[NSDate date]];
components.day    = 5;
components.hour   = 12;
components.minute = 30;

NSDate *fireDate = [calender dateFromComponents:components];

Upvotes: 1

Related Questions