0

我正在使用以下代码

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

我如何设置“fireDate”以便此通知仅在每月 5 号运行。其次,此代码位于 appDelegate.h 中。我将如何设置它以便它每月只启动一个通知

4

1 回答 1

1

我猜这个问题实际上是我如何创建一个日期对象来开始

你可以从这样的事情开始

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];
于 2013-01-13T21:47:42.973 回答