如何使用各种警报正文重复 UILocalNotification?
例如:
UILocalNotification *notif = [[UILocalNotification alloc] init];
notif.alertBody = @"Hello";
notif.repeatInterval = NSDayCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
通过使用此代码,通知将每天重复,我如何每天使用不同的警报正文重复通知?
Thanks.
你可以实施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];
}
只是一个选择,但希望它有所帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)