link1
link2
If I want to set local notification to repeat every 2 week than how to achieve this?
I have read several questions and answers here, they have mention to reschedule local notification but how to reschedule local notification while application is in background ?
I will appreciate any help on same.
Thanks.
To reschedule UILocal Notification use this ,
NSDateFormatter *dat= [[NSDateFormatter alloc]init];
[dat setLocale:[NSLocale currentLocale]];
[dat setTimeZone:[NSTimeZone systemTimeZone]];
//[dat setDateFormat:#"YYYY-MM-dd"];// YYYY-MM-dd hh:mm a
//NSString *dateM=[dat stringFromDate:datM];
//[dat setDateFormat:#"YYYY-MM-dd h:mm a"];
NSDate *reminderDate=[NSDate date];
//Use manual option too for timing
reminderDate =[reminderDate dateByAddingTimeInterval:1*24*60*60*7];
UILocalNotification *localnoification = [[UILocalNotification alloc]init];
localnoification.fireDate=reminderDate;
localnoification.timeZone = [NSTimeZone defaultTimeZone];
localnoification.alertBody = word;
localnoification.alertAction = #"Tap to see word of the day";
//May Add Custom Sound Also
//localnoification.soundName = UILocalNotificationDefaultSoundName;
localnoification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
//localnoification.applicationIconBadgeNumber = 1;
localnoification.repeatInterval = NSDayCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:localnoification];
Related
I need to show certain local notifications while app is in the background. How can I do it, without the help of NSNotificationCenter?
Andrey Chernukha in first comment is right.
Here is the code to implement simple Local Notification:
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.repeatInterval = 0;
NSDate *now = [NSDate date];
NSDate *dateToFire = [now dateByAddingTimeInterval:10];
localNotification.fireDate = dateToFire;
localNotification.alertBody = #"Test local notification";
localNotification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
I scheduled the Local notification for current day +1 and time say 10AM.When I change the device date to current day+1 and time 10PM then notification didn't show up.
Code is given below:
UILocalNotification * localNot = [[UILocalNotification alloc] init];
localNot.userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
#"ReminderId", #"REM01", nil];
localNot.alertBody = #"Alarm";
NSString *str =#"10/15/2014 9:15 AM";
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
formatter.timeZone = [NSTimeZone defaultTimeZone];
[formatter setDateFormat:#"MM/dd/yyyy hh:mm a"];
NSDate *date = [formatter dateFromString:str];
localNot.timeZone = [NSTimeZone defaultTimeZone];
localNot.fireDate = date;
localNot.repeatInterval = 0;
[[UIApplication sharedApplication] scheduleLocalNotification:localNot];
Need input.Thanks in advance.
Hello i am facing a weird kind problem. Actually i want to schedule a daily notification (only once a day) at 8:00 AM. Below is my code for scheduling daily notification.
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"HH:mm"];
NSDate *date = [[NSDate alloc] init];
date = [formatter dateFromString:#"08:00"];
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = date;
localNotification.timeZone=[NSTimeZone defaultTimeZone];
localNotification.alertBody = #"You just received a local notification";
localNotification.alertAction = #"View Details";
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.repeatInterval = NSDayCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
[formatter release];
[date release];
My problem is, I receive 2 local notifications. One at 8:00 AM and other at 10:00 AM. Why i am getting notification at 10:00 AM. I am scheduling it at 8:00 AM only. I know UILocalNotification library have some other weird kind of problems/bugs on most of apple devices. I just want to confirm whether there is some mistake in my code or it is a weird behaviour of UILocalNotification Library. I dont know why Apple is not working on resolving the issues being reported by many developers about UILocalNotification.
Note: I am using Xcode 4.6 and iOS 6.1
This would be the BEST link to get your answer.
I want to schedule UILocalNotificaion for 30 consecutive days at 8:00 AM daily and i want to implement that functionality with one UILocationNotification instance only. Here is my code to schedule local notification.
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"HH:mm"];
NSDate *date = [[NSDate alloc] init];
date = [formatter dateFromString:#"08:00"];
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = date;
localNotification.timeZone=[NSTimeZone defaultTimeZone];
localNotification.alertBody = #"You just received a local notification";
localNotification.alertAction = #"View Details";
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.repeatInterval = NSDayCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
[formatter release];
[date release];
It will fire daily notifications forever at 08:00AM, but i want to be notified for 30 consecutive days only. The easiest solution is to fire 30 UILocalNotifications but i want to do that with 1 UILocalNotification instance. How can i do that? Please help.
In UILocalNotification userInfo property save NSDate object when you create Notification.
When you open Notification,
check with the current date with date in userinfo . If there is difference is more than 30 days you can cancel your local notification.
NSDate *now = [NSDate date];
// now a NSDate object for now + 30 days
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];
[offsetComponents setDay:30];
NSDate *endDate = [gregorian dateByAddingComponents:offsetComponents toDate:now options:0];
After that check:
if([currentDate isEarlierDate:endDate]){
//Fire the notification
}
I am trying to schedule a notification to be delivered at 7 AM. But it gets delivered at 12 AM. Please help me what I am doing wrong. This is my code.
NSString *date = #"4/14/2013 07:00";
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:#"MM/dd/yyyy HH:mm"];
NSDate *thisDate = [df dateFromString:date];
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = thisDate;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.alertBody = #"This is notification";
localNotification.alertAction = #"view";
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.alertLaunchImage = Nil;
self.badgeCount ++;
localNotification.applicationIconBadgeNumber = self.badgeCount;
localNotification.userInfo = Nil;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
I expect this notification to be delivered at 7 AM. Instead it pops up at 12 AM. What is going wrong here ?
I bet localNotification.timeZone and df.timeZone are not the same...
Add this to your DateFormatter:
df.timeZone = [NSTimeZone defaultTimeZone];