如何在iphone中制作Schedule事件警报?
当天365天和五天的时间表。每天都有不同的时间
答案 0 :(得分:0)
使用这个想法
NSLog(@"clicked");
NSDate* date = [NSDate date];
NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateFormat:@"HH:MM:SS"]; //seting the date formater object
[formatter setTimeStyle:NSDateFormatterMediumStyle];
NSString* CorrectTime = [formatter stringFromDate:date]; //storing the date into string
NSLog(@"Current Time %@",CorrectTime);
[lab setText:CorrectTime];
if(!isValue){
NSTimeInterval seconds=10; //if 24 * 60 * 60 its for after 1day i.e. 24hrs,60min,60seconds
NSDate *changed;
changed = [date addTimeInterval:seconds];
af60= [formatter stringFromDate:changed];
NSLog(@"Changed time after 60s %@",af60);
isValue = TRUE;
NSDate *d = [NSDate dateWithTimeIntervalSinceNow: 5.0];
NSTimer *t = [[NSTimer alloc] initWithFireDate:d interval: 2 target: self selector:@selector(timerTick) userInfo:nil repeats:NO];
NSRunLoop *runner = [NSRunLoop currentRunLoop];
[runner addTimer:t forMode: NSDefaultRunLoopMode];
[t release];
}
}
- (void)timerTick{
NSLog(@"Time Out********************************&&&&&&&&&&&&&&&&&&&&");
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"alert" message:@"Yours Time Out" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"ok",nil];
[alert show];
}
这里我只加了10秒,10秒之后就会出现警报。像这样你应该发出警报
答案 1 :(得分:0)
您需要设置notification.repeatInterval
像这样NSInteger index = [scheduleControl selectedSegmentIndex];
switch (index) {
case 1:
notif.repeatInterval = NSMinuteCalendarUnit;
break;
case 2:
notif.repeatInterval = NSHourCalendarUnit;
break;
case 3:
notif.repeatInterval = NSDayCalendarUnit;
break;
case 4:
notif.repeatInterval = NSWeekCalendarUnit;
break;
default:
notif.repeatInterval = 0;
break;
}
这会对你有所帮助 http://useyourloaf.com/blog/2010/9/13/repeating-an-ios-local-notification.html 谢谢, 函数naveed
答案 2 :(得分:0)
您需要为代码设置notification.repeatInterval
像这样NSInteger index = [scheduleControl selectedSegmentIndex];
switch (index) {
case 1:
notif.repeatInterval = NSMinuteCalendarUnit;
break;
case 2:
notif.repeatInterval = NSHourCalendarUnit;
break;
case 3:
notif.repeatInterval = NSDayCalendarUnit;
break;
case 4:
notif.repeatInterval = NSWeekCalendarUnit;
break;
default:
notif.repeatInterval = 0;
break;
}
这会对你有所帮助 http://useyourloaf.com/blog/2010/9/13/repeating-an-ios-local-notification.html 谢谢, 函数naveed