added NSBluetoothPeripheralUsageDescription to info.plist and code cleanup for self.requestNotificationAuthorization

This commit is contained in:
Johan Degraeve 2019-05-26 23:50:13 +02:00
parent 5df1e75a17
commit ac288f973e
2 changed files with 10 additions and 26 deletions

View File

@ -17,11 +17,13 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>APPL</string> <string>APPL</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>2.0.0</string> <string>2.0.1</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>2.0.0</string> <string>2.0.1</string>
<key>LSRequiresIPhoneOS</key> <key>LSRequiresIPhoneOS</key>
<true/> <true/>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>Connect to CGM Transmitter</string>
<key>UIBackgroundModes</key> <key>UIBackgroundModes</key>
<array> <array>
<string>audio</string> <string>audio</string>

View File

@ -42,9 +42,6 @@ final class RootViewController: UIViewController {
/// for logging /// for logging
private var log = OSLog(subsystem: Constants.Log.subSystem, category: Constants.Log.categoryFirstView) private var log = OSLog(subsystem: Constants.Log.subSystem, category: Constants.Log.categoryFirstView)
/// did user authorize notifications ?
private var notificationsAuthorized:Bool = false;
/// coreDataManager to be used throughout the project /// coreDataManager to be used throughout the project
private var coreDataManager:CoreDataManager? private var coreDataManager:CoreDataManager?
@ -127,18 +124,14 @@ final class RootViewController: UIViewController {
// check if app is allowed to send local notification and if not ask it // check if app is allowed to send local notification and if not ask it
UNUserNotificationCenter.current().getNotificationSettings { (notificationSettings) in UNUserNotificationCenter.current().getNotificationSettings { (notificationSettings) in
switch notificationSettings.authorizationStatus { switch notificationSettings.authorizationStatus {
case .notDetermined: case .notDetermined, .denied:
self.requestNotificationAuthorization(completionHandler: { (success) in UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (success, error) in
guard success else { if let error = error {
os_log("failed to request notification authorization", log: self.log, type: .info) os_log("Request Notification Authorization Failed : %{public}@", log: self.log, type: .error, error.localizedDescription)
return
} }
self.notificationsAuthorized = true }
})
case .denied:
os_log("notification authorization denied", log: self.log, type: .info)
default: default:
self.notificationsAuthorized = true break
} }
} }
@ -202,17 +195,6 @@ final class RootViewController: UIViewController {
} }
/// request notification authorization to the user for alert, sound and badge
private func requestNotificationAuthorization(completionHandler: @escaping (_ success: Bool) -> ()) {
// Request Authorization
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (success, error) in
if let error = error {
os_log("Request Notification Authorization Failed : %{public}@", log: self.log, type: .error, error.localizedDescription)
}
completionHandler(success)
}
}
private func processNewCGMInfo(glucoseData: inout [RawGlucoseData], sensorState: SensorState?, firmware: String?, hardware: String?, transmitterBatteryInfo: TransmitterBatteryInfo?, sensorTimeInMinutes: Int?) { private func processNewCGMInfo(glucoseData: inout [RawGlucoseData], sensorState: SensorState?, firmware: String?, hardware: String?, transmitterBatteryInfo: TransmitterBatteryInfo?, sensorTimeInMinutes: Int?) {
// check that calibrations and coredata manager is not nil // check that calibrations and coredata manager is not nil