我想它是用UILocalNotification設定重複提示所做成的。
以下是實現代碼
// 獲得當前的時分秒
NSDate* now = [NSDate date];
NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"HH:mm:ss"];
NSString* nowTime = [formatter stringFromDate:now];
NSDate* nowDate = [formatter dateFromString:nowTime];
[formatter release];
NSArray* strArr = [NSArray arrayWithObjects:@"Sunday", @"Monday", @"Tuesday", @"Wednesday", @"Thursday", @"Friday", @"Saturday", nil];
for(NSUInteger i = 0; i < 7; i++)
{
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
if (localNotification == nil)
continue;
// 設定提示日期,本來日期已過Local Notification是不可被schedule的,
// 重複是例外,我以1970年1月1日為單位加3天就是星期天,
// 再加上今天我時間差,就可以每天都是在同一時間來重複提示
localNotification.fireDate = [NSDate dateWithTimeIntervalSince1970:60*60*24*(3+i)+[nowDate timeIntervalSince1970]];
localNotification.alertBody = [strArr objectAtIndex:i];
// 設定每星期也重複
localNotification.repeatCalendar = [NSCalendar currentCalendar]; localNotification.repeatInterval = NSWeekdayCalendarUnit;
localNotification.alertAction = @"View";
localNotification.soundName = UILocalNotificationDefaultSoundName; [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; [localNotification release];
}
NSDate* now = [NSDate date];
NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"HH:mm:ss"];
NSString* nowTime = [formatter stringFromDate:now];
NSDate* nowDate = [formatter dateFromString:nowTime];
[formatter release];
NSArray* strArr = [NSArray arrayWithObjects:@"Sunday", @"Monday", @"Tuesday", @"Wednesday", @"Thursday", @"Friday", @"Saturday", nil];
for(NSUInteger i = 0; i < 7; i++)
{
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
if (localNotification == nil)
continue;
// 設定提示日期,本來日期已過Local Notification是不可被schedule的,
// 重複是例外,我以1970年1月1日為單位加3天就是星期天,
// 再加上今天我時間差,就可以每天都是在同一時間來重複提示
localNotification.fireDate = [NSDate dateWithTimeIntervalSince1970:60*60*24*(3+i)+[nowDate timeIntervalSince1970]];
localNotification.alertBody = [strArr objectAtIndex:i];
// 設定每星期也重複
localNotification.repeatCalendar = [NSCalendar currentCalendar]; localNotification.repeatInterval = NSWeekdayCalendarUnit;
localNotification.alertAction = @"View";
localNotification.soundName = UILocalNotificationDefaultSoundName; [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; [localNotification release];
}
沒有留言:
張貼留言