您可以application:didReceiveLocalNotification
在 AppDelegate 中实现该方法,并增加一个“日计数器”变量。然后,UILocalNotification
为通知的警报正文安排一个包含字符串数组的新消息。使用日期计数器获取更新的字符串。这是一些示例代码:
在您的 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];
}
只是一个选择,但希望它有所帮助。