I am creating an app by collecting 365 english "sayings".In my app i would like to use local notifications(everyday a sayings from my app should be notified to the user).i would like to use local notification ,not push notification.is it possible to notify the user with different sayings each day(365 days) .Can anyone help me please.....
Asked
Active
Viewed 1,113 times
1
-
You can only set 64 [`UILocalNotifications`](http://developer.apple.com/library/ios/#documentation/iPhone/Reference/UILocalNotification_Class/Reference/Reference.html) for you application. – rckoenes Jun 05 '13 at 09:40
-
1and this is Apple's official tutorial: http://developer.apple.com/library/ios/#DOCUMENTATION/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW13 – Raptor Jun 05 '13 at 09:41
-
1Go through the tutorial mentioned in the link by Adi, and the logic would be save the sayings into a database and pick a new saying everytime the notification is fired. Easiest way would be to use index as the day of year to read from the database. – Praveen S Jun 05 '13 at 09:41
2 Answers
1
There is no way to create 365 different local notification. According to the documentation local notification is limited to 64 scheduled local notifications.
But you can update notifications, when user launch your app. If content of notifications is the same, you can also schedule the notification for delivery on a recurring basis

German Saprykin
- 6,631
- 2
- 29
- 26
-
If I add recurring interval as month and add 31 local notification. Will this work fine?? Or 1st of the month there will be 2 notification?? – Ajith Kumar Aug 24 '20 at 10:49
0
Yes you can.Just create array with 365 dictionaries. dictionary keys should be id and saying.
UILocalNotification *localNotif = [[UILocalNotification alloc]init];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDate *datePickerDate = [NSDate date];
NSDateComponents *dateComponents = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:datePickerDate];
NSDateComponents *timeComponents = [calendar components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate:datePickerDate];
NSDateComponents *dateComps = [[NSDateComponents alloc]init];
[dateComps setYear:[dateComponents year]];
[dateComps setMonth:[dateComponents month]];
[dateComps setDay:[dateComponents day] + 1];
[dateComps setHour:[timeComponents hour] ];
[dateComps setMinute:[timeComponents minute]];
[dateComps setSecond:00];
NSDate *fireDate = [calendar dateFromComponents:dateComps];
//NSLog(@"%@",fireDate);
localNotif.fireDate = fireDate;
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.alertAction = @"Alarm";
localNotif.repeatInterval = NSDayCalendarUnit;
localNotif.userInfo = [NSDictionary dictionaryWithObjectsAndKeys:@"1",@"id", nil];
localNotif.alertBody = [saying with id 1];//you can use predicate here
[[UIApplication sharedApplication]scheduleLocalNotification:localNotif];
in application delegate,
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
int i = [[localNotif.userInfo objectForKey:@"id"] intValue] + 1;
localNotif.alertBody = [saying in index i ];
[localNotif.userInfo setValue:i forKey:@"id"];
}

manujmv
- 6,450
- 1
- 22
- 35
-
There are many problems with your code, first you can only register 64 notifications, Seconde the `application:didReceiveLocalNotification:` will only fire if you app is running when the notification is trigged. – rckoenes Jun 05 '13 at 12:37
-
@rckoenes: thank you for your comment. 1. actually it was not 365 notifications. just one notification with repeat interval every day. 2. you are right. application:didReceiveLocalNotification: only invokes when user receives it. but it was the only possibility. otherwise how can u achieve this? – manujmv Jun 05 '13 at 13:19
-
well that is the problem right. Just having the 64 registered notifications. Also you might want to check if the app was start with a local notification in the `application:didFinishLaunchingWithOptions:` by checking of the options contains a local notification. One way you could make it work is to register 64 notification on every start of the app, that way the app will always work 63 day's after the last launch. But again not 100% reliable. – rckoenes Jun 05 '13 at 13:23