与各种警报机构的UILocalNotification

如何重复UILocalNotification与各种警报机构?

例如:

UILocalNotification *notif = [[UILocalNotification alloc] init]; notif.alertBody = @"Hello"; notif.repeatInterval = NSDayCalendarUnit; [[UIApplication sharedApplication] scheduleLocalNotification:notif]; 

通过使用这个代码,通知将会每天重复,我怎样才能每天重复通知不同的警报机构?

谢谢。

你可以在AppDelegate中实现application:didReceiveLocalNotification方法,并增加一个“day counter”variables。 然后,为您的通知的警报正文安排一个新的UILocalNotification与一个string数组。 使用date计数器来获取更新的string。 以下是一些示例代码:

在你的AppDelegate.h中:

 @property (assign, nonatomic) int dayCount; 

在你的AppDelegate.m中:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. [self scheduleLocalNotification]; return YES; } -(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{ self.dayCount++; [self scheduleLocalNotification]; } -(void)scheduleLocalNotification{ NSArray *notifTextArray = [NSArray arrayWithObjects:@"Hello", @"Welcome", @"Hi there", nil]; UILocalNotification *notif = [[UILocalNotification alloc] init]; if(self.dayCount < notifTextArray.count){ notif.alertBody = [notifTextArray objectAtIndex:self.dayCount]; } else{ self.dayCount = 0; notif.alertBody = [notifTextArray objectAtIndex:self.dayCount]; } notif.fireDate = [NSDate dateWithTimeIntervalSinceNow:86400]; //86400 seconds in a day [[UIApplication sharedApplication] scheduleLocalNotification:notif]; } 

只是一个select,但希望它有帮助。

一旦您安排了本地通知,您就无法更改通知和警报主体的任何属性。

您可能不得不取消旧的通知,并重新安排一个新的通知来达到这个目的。