Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #import "TRNotificationManager.h"
  2. #define GOAL_PRESENTED_KEY @"goalPresentedKey"
  3.  
  4. @implementation TRNotificationManager
  5.  
  6. #pragma mark - UILocalNotification
  7.  
  8. - (void)presentGoalCompletionNotification {
  9. if (!self.isGoalNotificationPresentedToday) {
  10. UILocalNotification *notification = [[UILocalNotification alloc] init];
  11. if (notification) {
  12. notification.alertBody = @"You've reached your daily goal. Well done!";
  13. notification.alertAction = @"View Details";
  14. notification.soundName = UILocalNotificationDefaultSoundName;
  15. [[UIApplication sharedApplication] presentLocalNotificationNow:notification];
  16. self.goalNotificationPresentedToday = YES;
  17. [Flurry logEvent:@"Goal completion notification"];
  18. }
  19. }
  20. }
  21.  
  22. - (BOOL)isGoalNotificationPresentedToday {
  23. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  24. return ([(NSDate *)[defaults objectForKey:GOAL_PRESENTED_KEY] isToday]) ? YES : NO;
  25. }
  26.  
  27. - (void)setGoalNotificationPresentedToday:(BOOL)goalNotificationPresented {
  28. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  29. NSDate *date = (goalNotificationPresented) ? [NSDate date] : [NSDate dateWithTimeIntervalSinceReferenceDate:0];
  30. [defaults setObject:date forKey:GOAL_PRESENTED_KEY];
  31. [defaults synchronize];
  32. }
  33.  
  34. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement