I have a question about whether an observer for NSCalendarDayChanged can function when the app is in the background. The following code only triggers when 1) the date changes AND 2) the app is subsequently brought to the foreground.
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(calendarDayDidChange(notification:)), name: .NSCalendarDayChanged, object: nil)
}
@objc func calendarDayDidChange(notification : NSNotification) {
//Do something
print("The date has changed. Uploading yesterday's data...")
}
}
From the documentation: https://developer.apple.com/documentation/foundation/nsnotification/name/1408062-nscalendardaychanged