Guest User

Untitled

a guest
Oct 17th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. - (void)scheduleNotification:(ANSNotificationMO *)notification content:(UNMutableNotificationContent *)content repeats:(BOOL)repeats {
  2.  
  3.  
  4. ANSNotificationMO *notificationForFunction = notification;
  5.  
  6. [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge)
  7. completionHandler:^(BOOL granted, NSError * _Nullable error) {
  8.  
  9. // UNMutableNotificationContent *notificationContent = [self notificationContentForNotification:notification];
  10. // if (userInfo) {
  11. // notificationContent.userInfo = userInfo;
  12. // }
  13. if (content) {
  14. // schedule with UNUserNotificationCenter
  15. NSDateComponents *fireDateComps = [self fireDateComponentsForNotification:notificationForFunction];
  16.  
  17.  
  18. UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:fireDateComps repeats:repeats];
  19.  
  20. UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:notificationForFunction.requestIdentifier content:content trigger:trigger];
  21.  
  22. [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
  23.  
  24. if (error) {
  25. CLS_LOG(@"Notification Scheduling Error: %@", error);
  26. [Answers logCustomEventWithName:@"UNUserNotificationError" customAttributes:@{@"error":error.description,
  27. @"method":@"scheduleNotification:(ANSNotificationMO *)notification userInfo:(NSDictionary *)userInfo repeats:"
  28. }];
  29.  
  30. } else {
  31. // [_dataController saveContext];
  32. // [_rescheduler requestDescheduleForNotification:notification];
  33. }
  34. }];
  35. }
  36. }];
  37. }
Add Comment
Please, Sign In to add comment