mobile-ios/CovidSafe/OnboardingStep2ViewController.swift

47 lines
1.7 KiB
Swift
Raw Normal View History

2020-05-08 07:49:14 +00:00
//
// OnboardingStep2ViewController.swift
// CovidSafe
//
// Copyright © 2020 Australian Government. All rights reserved.
//
import UIKit
2020-06-05 00:26:40 +00:00
import CoreBluetooth
2020-05-08 07:49:14 +00:00
import UserNotifications
class OnboardingStep2ViewController: UIViewController {
2020-06-05 00:26:40 +00:00
private var bluetoothDidUpdateStateCallback: ((CBManagerState) -> Void)?
2020-05-08 07:49:14 +00:00
@IBAction func onBackTapped(_ sender: UIButton) {
self.navigationController?.popViewController(animated: true)
}
2020-06-05 00:26:40 +00:00
@IBAction func proceedTapped(_ sender: UIButton) {
self.bluetoothDidUpdateStateCallback = BluetraceManager.shared.bluetoothDidUpdateStateCallback
BluetraceManager.shared.bluetoothDidUpdateStateCallback = centralDidUpdateStateCallback
BluetraceManager.shared.turnOn()
UserDefaults.standard.set(true, forKey: "turnedOnBluetooth")
}
func centralDidUpdateStateCallback(_ state: CBManagerState) {
DLog("state changed in permission request to \(BluetraceUtils.centralStateToString(state))")
requestPushPermissions()
}
func requestPushPermissions() {
BluetraceManager.shared.bluetoothDidUpdateStateCallback = self.bluetoothDidUpdateStateCallback
UNUserNotificationCenter.current()
.requestAuthorization(options: [.alert, .sound, .badge]) {
granted, error in
2020-07-21 05:42:48 +00:00
2020-06-05 00:26:40 +00:00
UserDefaults.standard.set(true, forKey: "allowedPermissions")
print("Permissions granted: \(granted)")
DispatchQueue.main.async {
2020-07-21 05:42:48 +00:00
UIApplication.shared.registerForRemoteNotifications()
2020-06-05 00:26:40 +00:00
self.performSegue(withIdentifier: "showSuccessSegue", sender: self)
}
}
}
2020-05-08 07:49:14 +00:00
}