     
     public func clearBadgeNumberAndRemoveAllNotifications() {
         clearBadgeNumber()
-        removeAllNotifications()
+        notificationScheduler.removeAllNotifications()
     }
     
     private func clearBadgeNumber() {

        }
        UIApplication.shared.applicationIconBadgeNumber = 0
    }
    
    private func removeAllNotifications() {
        if #available(iOS 10.0, *) {
            os_log("Removing all notifications", type: .debug)
        }
        
        if #available(iOS 10.0, *) {
            let center = UNUserNotificationCenter.current()
            center.removeAllPendingNotificationRequests()
            center.removeAllDeliveredNotifications()
        } else {
            let application = UIApplication.shared
            application.cancelAllLocalNotifications()
        }
    }
    
    private func scheduleNotification(at date: Date, badgeNumber: Int) {
        if #available(iOS 10.0, *) {
            os_log("Scheduling local notification with badge number %d at %@", type: .debug, badgeNumber, date as NSDate)
        }
        
        if #available(iOS 10.0, *) {
            let content = UNMutableNotificationContent()
            content.badge = badgeNumber as NSNumber
            
            let dateComponents = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute, .second], from: date)
            let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: false)
            
            let request = UNNotificationRequest(identifier: "ACBadge-\(badgeNumber)", content: content, trigger: trigger)
            let center = UNUserNotificationCenter.current()
            center.add(request, withCompletionHandler: nil)
        } else {
            let localNotification = UILocalNotification()
            localNotification.fireDate = date
            localNotification.applicationIconBadgeNumber = badgeNumber
            
            UIApplication.shared.scheduleLocalNotification(localNotification)
        }
    }
    
    private func scheduleNotification(at date: Date, body: String) {
        if #available(iOS 10.0, *) {
            os_log("Scheduling local notification at %@", type: .debug, date as NSDate)
        }
        
        if #available(iOS 10.0, *) {
            let content = UNMutableNotificationContent()
            content.body = body
            content.sound = UNNotificationSound.default()
            
            let dateComponents = Calendar.current.dateComponents([.era, .year, .month, .day, .hour, .minute, .second], from: date)
            let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: false)
            
            let request = UNNotificationRequest(identifier: "ACText", content: content, trigger: trigger)
            let center = UNUserNotificationCenter.current()
            center.add(request, withCompletionHandler: nil)
        } else {
            let localNotification = UILocalNotification()
            localNotification.fireDate = date
            localNotification.alertBody = body
            localNotification.soundName = UILocalNotificationDefaultSoundName
            
            UIApplication.shared.scheduleLocalNotification(localNotification)
        }
    }
}

import WaniKaniKit

class NotificationManager {
    private let notificationScheduler: NotificationScheduler
    private var assignmentsChangeObserver: NSObjectProtocol?
    
    init() {
        if #available(iOS 10.0, *) {
            notificationScheduler = UserNotificationScheduler()
        } else {
            notificationScheduler = LocalNotificationScheduler()
        }
    }
    
    deinit {
        unregisterForNotifications()
    }
    
    public func registerForNotifications(resourceRepository: ResourceRepositoryReader) {
        notificationScheduler.requestAuthorisation { (granted, error) in
            if let error = error {
                if #available(iOS 10.0, *) {
                    os_log("Got error from notification authorisation: %@", type: .error, error as NSError)
                }
            }
            if #available(iOS 10.0, *) {
                os_log("Notification authorisation granted = %@", type: .info, String(granted))
            }
            
            if granted {
                self.listenForAssignmentChanges(resourceRepository: resourceRepository)
            }
        }
    }
    
