UILocalNotification结束日期

我想知道是否可以设置UILocalNotification结束日期?

我希望我的通知每天都要开火( NSDayCalendarUnit ),但我有结束日期,我无法跨越(截止日期),例如,我每天拍摄一张我日益增长的小胡子的照片,一年后,通知将不会显示。

我希望你有我的观点……

UILocalNotification没有这样的选项,因为您可以在文档中阅读。

您唯一的选择是在每个用户启动应用程序时检查年份是否结束。

UILocalNotification对象中,我建议设置repeatInterval属性并将结束日期放在userInfo字典中以便稍后查询以确定通知是否已过期。 例如:

 UILocalNotification* uiLocalNotification; uiLocalNotification = [[UILocalNotification alloc] init]; //Set the repeat interval uiLocalNotification.repeatInterval = NSCalendarUnitDay; NSDate* fireDate = ... //Set the fire date uiLocalNotification.fireDate = fireDate; //Set the end date NSDate* endDate = ... uiLocalNotification.userInfo = @{ @"endDate": endDate }; UIApplication* application = [UIApplication sharedApplication]; [application scheduleLocalNotification:uiLocalNotification]; //... //Somewhere else in your codebase, query for the expiration and cancel, if necessary UIApplication* application = [UIApplication sharedApplication]; NSArray* scheduledNotifications = application.scheduledLocalNotifications; NSDate* today = [NSDate date]; for (UILocalNotification* notification in scheduledNotifications) { NSDate* endDate = notification.userInfo[@"endDate"]; if ([today earlierDate:endDate] == endDate) { //Cancel the notification [application cancelLocalNotification:notification]; } } 
 Use following code: UILocalNotification *localNotification = [[UILocalNotification alloc] init]; localNotification.repeatInterval = NSDayCalendarUnit;