How i can ma开发者_如何学Cke Schedule event alarm in iphone?
Schedule for 365 days and five time in the day. every days have different time
use this idea
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];
}
here i added only 10 sec, after 10 sec it wil pops alertview. like this u should fire your alarm
You need to set the notification.repeatInterval
like this
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;
}
This will help you http://useyourloaf.com/blog/2010/9/13/repeating-an-ios-local-notification.html Thanks, Naveed
You need to set the notification.repeatInterval for your code
like this
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;
}
This will help you http://useyourloaf.com/blog/2010/9/13/repeating-an-ios-local-notification.html Thanks, Naveed
精彩评论