//
//  SegmentAnalytics+Notifications.swift
//  SegmentAnalytics
//
//  Created by Alex Zchut on 22/11/2021.
//

import Foundation

extension SegmentAnalytics {
    func addNotificationsObserver() {
        let defaultCenter = NotificationCenter.default

        defaultCenter.addObserver(self,
                                  selector: #selector(applicationWillResignActive(notification:)),
                                  name: UIApplication.willResignActiveNotification,
                                  object: nil)

        defaultCenter.addObserver(self,
                                  selector: #selector(applicationDidBecomeActive(notification:)),
                                  name: UIApplication.didBecomeActiveNotification,
                                  object: nil)
    }

    @objc func applicationWillResignActive(notification _: Notification) {
        canSendScreenHeartbeatEvent = false
    }

    @objc func applicationDidBecomeActive(notification _: Notification) {
        canSendScreenHeartbeatEvent = true
    }
}
