Reputation: 19
iam getting some date and time like appointment time. i want to remind the user before to that particular time.i googled and got some knowledge but still in small confusion where to write my code shall i in application entered back ground method and i have to use alert views or any other .please help me.
NSString *today=[NSString stringWithFormat:@"%@ %@",appDelegate.appointmentDate,appDelegate.timeStart1];
NSLog(@"%@",today);
NSDateFormatter *format=[[NSDateFormatter alloc]init];
[format setDateFormat:@"MM/dd/yyyy hh:mm a"];
NSDate *date1=[format dateFromString:today];
NSLog(@"%@",date1);
NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *datefo1 =[[NSDateComponents alloc]init];
[datefo1 setMinute:1];
[datefo1 setSecond:0];
NSDate *alerttime=[cal dateByAddingComponents:datefo1 toDate:date options:0];
UIApplication* app = [UIApplication sharedApplication];
UILocalNotification* notifyAlarm = [[UILocalNotification alloc]
init];
if (notifyAlarm)
{
notifyAlarm.fireDate = alerttime;
notifyAlarm.timeZone = [NSTimeZone defaultTimeZone];
notifyAlarm.repeatInterval = 0;
notifyAlarm.alertBody = @"you have an appointment in 30 minutes";
[app scheduleLocalNotification:notifyAlarm];
}
i want notification like on top i want to display some alert even my app is running and not running also. but its coming with out any message, where i am going wrong shall i need to use nsnotification center are some thing else. sorry for my poor english.thanks in advance
Upvotes: 0
Views: 113
Reputation: 119031
You're using local notifications, which is a good start, but you should know that local notifications are only displayed if your app is in the background. If your app is running in the foreground when the time comes you will need to display the notification yourself (UIView / UIAlertView).
You can schedule the local notification whenever you want, it really depends what editing you allow the user to do and, therefore, how much you might need to cancel the local notification and schedule a new version.
Few other things:
Upvotes: 1