mirror of
https://github.com/AU-COVIDSafe/mobile-ios.git
synced 2025-04-19 13:05:21 +00:00
COVIDSafe code from version 1.6 (#6)
This commit is contained in:
parent
149daee2e9
commit
2063cea613
38 changed files with 1963 additions and 1664 deletions
|
@ -26,6 +26,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||
UserDefaults.standard.set(true, forKey: "HasBeenLaunched")
|
||||
}
|
||||
|
||||
UIBarButtonItem.appearance().setTitleTextAttributes([.foregroundColor: UIColor.covidSafeColor], for: .normal)
|
||||
UINavigationBar.appearance().tintColor = UIColor.covidSafeColor
|
||||
|
||||
let hasUserConsent = true
|
||||
let hasUserCompletedOnboarding = UserDefaults.standard.bool(forKey: "turnedOnBluetooth")
|
||||
let bluetoothAuthorised = BluetraceManager.shared.isBluetoothAuthorized()
|
||||
|
@ -98,13 +101,33 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||
if !UserDefaults.standard.bool(forKey: "sentBluetoothStatusNotif") {
|
||||
UserDefaults.standard.set(true, forKey: "sentBluetoothStatusNotif")
|
||||
self.triggerIntervalLocalPushNotifications(pnContent: PushNotificationConstants.btStatusPushNotifContents[btStatusMagicNumber], identifier: "bluetoothStatusNotifId")
|
||||
return
|
||||
}
|
||||
}
|
||||
switch state {
|
||||
case .poweredOff, .unauthorized:
|
||||
DLog("*** Setup reminders - BL OFF, UNAUTH check/set reminders")
|
||||
self.checkAndScheduleReminderNotifications()
|
||||
default:
|
||||
// leave reminder notifications as they are, when an encounter occurs the notifications will be deferred
|
||||
// or removed when app becomes active
|
||||
DLog("*** Setup reminders - Default leave reminders")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate func cancelPreviouslyScheduledNotifications() {
|
||||
UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
|
||||
fileprivate func getReminderNotificationsIdentifiers() -> [String] {
|
||||
var identifiers: [String] = []
|
||||
for interval in intervals {
|
||||
identifiers.append(getReminderNotificationIdentifier(interval: interval))
|
||||
}
|
||||
return identifiers
|
||||
}
|
||||
|
||||
fileprivate func cancelScheduledReminderNotifications() {
|
||||
DLog("*** Cancel reminders")
|
||||
let identifiers = getReminderNotificationsIdentifiers()
|
||||
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: identifiers)
|
||||
}
|
||||
|
||||
fileprivate func triggerIntervalLocalPushNotifications(pnContent: [String : String], identifier: String) {
|
||||
|
@ -128,8 +151,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||
let intervals: [TimeInterval] = [TimeInterval(60 * 60 * 48)]
|
||||
#endif
|
||||
|
||||
fileprivate func scheduleReminderNotifications() {
|
||||
fileprivate func getReminderNotificationIdentifier(interval: TimeInterval) -> String {
|
||||
return "reminder-\(interval)"
|
||||
}
|
||||
|
||||
fileprivate func checkAndScheduleReminderNotifications() {
|
||||
let identifiers = getReminderNotificationsIdentifiers()
|
||||
DLog("*** Setup reminders - checking pending reminders")
|
||||
// check all reminders are scheduled and pending
|
||||
UNUserNotificationCenter.current().getPendingNotificationRequests { (notificationsRequest) in
|
||||
var scheduledRemindersCount = 0
|
||||
for notification in notificationsRequest {
|
||||
if identifiers.firstIndex(of: notification.identifier) != nil {
|
||||
scheduledRemindersCount += 1
|
||||
}
|
||||
}
|
||||
// re-schedule reminders unless they are all pending
|
||||
if scheduledRemindersCount != identifiers.count {
|
||||
self.scheduleReminderNotifications()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate func scheduleReminderNotifications() {
|
||||
DLog("*** Set reminders")
|
||||
let reminderContent = PushNotificationConstants.reminderPushNotifContents
|
||||
guard
|
||||
let title = reminderContent["contentTitle"],
|
||||
|
@ -141,7 +186,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||
|
||||
for interval in intervals {
|
||||
let content = UNMutableNotificationContent()
|
||||
|
||||
let identifier = getReminderNotificationIdentifier(interval: interval)
|
||||
#if DEBUG
|
||||
content.title = "\(title) \(interval / 60) min"
|
||||
#else
|
||||
|
@ -152,14 +197,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||
|
||||
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: interval, repeats: false)
|
||||
|
||||
let request = UNNotificationRequest(identifier: "reminder-\(interval)", content: content, trigger: trigger)
|
||||
let request = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger)
|
||||
notificationCenter.add(request)
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
func deferReminderNotifications(_ notification: Notification) {
|
||||
cancelPreviouslyScheduledNotifications()
|
||||
// no need to cancel, if same ID used the notification is updated
|
||||
scheduleReminderNotifications()
|
||||
}
|
||||
|
||||
|
@ -168,13 +213,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||
|
||||
startAccelerometerUpdates()
|
||||
clearOldDataInContext()
|
||||
|
||||
// if Bluetooth is ON, remove reminders, leave otherwise.
|
||||
if BluetraceManager.shared.isBluetoothOn() {
|
||||
cancelScheduledReminderNotifications()
|
||||
}
|
||||
}
|
||||
|
||||
func applicationWillResignActive(_ application: UIApplication) {
|
||||
DLog("applicationWillResignActive")
|
||||
// Retry in case it failed on become active
|
||||
clearOldDataInContext()
|
||||
scheduleReminderNotifications()
|
||||
|
||||
// check if reminders pending and set if needed
|
||||
checkAndScheduleReminderNotifications()
|
||||
}
|
||||
|
||||
func applicationDidEnterBackground(_ application: UIApplication) {
|
||||
|
@ -187,8 +239,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||
func applicationWillEnterForeground(_ application: UIApplication) {
|
||||
DLog("applicationWillEnterForeground")
|
||||
self.dismissBlackscreen()
|
||||
|
||||
cancelPreviouslyScheduledNotifications()
|
||||
}
|
||||
|
||||
func applicationWillTerminate(_ application: UIApplication) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue