0

I gather that IOS does not give you access to the notifications center in order to keep track of notitifications.

However, many apps do seem to keep track of notifications so that when you see the badge on your home screen or a notification fires and you tap inside the app you can view all the notifications. Linkedin does this for example.

In my case, all the notifications refer to managedobjects in one entity in core data so I tried to hack this by estimating which notifications should have fired given their timestamps in core data. However, this is proving to be an unreliable approach. A fetch that grabbed every item beginning with the first notification since last opened would have to know the time stamp of the first notification since last opened. However, while you know the current time, you don't really know the time of the first notification if you don't know what the first notification since the last opening of the app is.

Has anyone devised a way or know of a library to accurately track notifications? It occurred to me one way might be create an accessible doppelganger of the notificationcenter in core data or an array and keep the notifications there. But that's as far as I've gotten.

To create the cache of future notifications in the notification center, I just fetch anything with a date in the future from core data and add the notification to the notification center:

NSDate *now [NSDate* date];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"event!=nil AND event.length>=1&&starttime>=now"];
//perform fetch code here
 NSInteger resultCount = [fetchedObjects count];
UILocalNotification *reminderNotification;
  for (int i = 0; i < resultCount; i++) {
 reminderNotification = [[UILocalNotification alloc] init];
                reminderNotification.fireDate = event.starttime;
                reminderNotification.timeZone = [NSTimeZone defaultTimeZone];
                reminderNotification.alertAction = @"View Event";
               reminderNotification.alertBody = event.event;
                reminderNotification.applicationIconBadgeNumber = resultCount+1;
                //schedule the notification!
                [[UIApplication sharedApplication] 

scheduleLocalNotification:reminderNotification];     
       resultCount++;
}

Thanks in advance for any suggestions.

user6631314
  • 1,751
  • 1
  • 13
  • 44
  • 1
    Look at `UNUserNotificationCenter` – dan Apr 18 '18 at 16:24
  • If these are local notifications, then why not have your app keep a list of everything it's sent a notification about, that gets cleared whenever it responds to the notifications, or when the app opens or whenever it makes sense? – Tom Harrington Apr 18 '18 at 19:56
  • Would you just do this in an NSMutableArray? – user6631314 Apr 18 '18 at 20:41
  • @dan, I am supporting <10. Is it feasible to run UNUserNotificationCenter simultaneously with regular UILocationNotifications? Should I do a test on IOS version and if they have 10+, use unnotification center, otherwise use existing code? – user6631314 Apr 18 '18 at 20:44

0 Answers0