Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "TRNotificationManager.h"
- #define GOAL_PRESENTED_KEY @"goalPresentedKey"
- @implementation TRNotificationManager
- #pragma mark - UILocalNotification
- - (void)presentGoalCompletionNotification {
- if (!self.isGoalNotificationPresentedToday) {
- UILocalNotification *notification = [[UILocalNotification alloc] init];
- if (notification) {
- notification.alertBody = @"You've reached your daily goal. Well done!";
- notification.alertAction = @"View Details";
- notification.soundName = UILocalNotificationDefaultSoundName;
- [[UIApplication sharedApplication] presentLocalNotificationNow:notification];
- self.goalNotificationPresentedToday = YES;
- [Flurry logEvent:@"Goal completion notification"];
- }
- }
- }
- - (BOOL)isGoalNotificationPresentedToday {
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- return ([(NSDate *)[defaults objectForKey:GOAL_PRESENTED_KEY] isToday]) ? YES : NO;
- }
- - (void)setGoalNotificationPresentedToday:(BOOL)goalNotificationPresented {
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- NSDate *date = (goalNotificationPresented) ? [NSDate date] : [NSDate dateWithTimeIntervalSinceReferenceDate:0];
- [defaults setObject:date forKey:GOAL_PRESENTED_KEY];
- [defaults synchronize];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement