Updated location usage description, post sent gps fixes notifications and subscribe to them in training controller

This commit is contained in:
Raimund Wege
2017-12-20 16:59:12 +01:00
parent 9892f84f7b
commit f47b9ca2a8
5 changed files with 85 additions and 7 deletions
@@ -6,6 +6,7 @@
// Copyright © 2016 com.sap.sailing. All rights reserved.
//
"NSLocationAlwaysUsageDescription" = "In order to track your entire race your phone needs to continue tracking also when you switch off or lock the screen which helps save battery and avoids unintentionally stopping the tracking process.";
"NSLocationWhenInUseUsageDescription" = "In order to track your entire race your phone needs to continue tracking also when you switch off or lock the screen which helps save battery and avoids unintentionally stopping the tracking process.";
"NSLocationAlwaysAndWhenInUseUsageDescription" = "In order to track your entire race your phone needs to continue tracking also when you switch off or lock the screen which helps save battery and avoids unintentionally stopping the tracking process.";
"NSCameraUsageDescription" = "The camera is required to perform a check-in using QR code.";
"NSPhotoLibraryUsageDescription" = "To replace the Team Photo the app requires access to the photo library.";
@@ -12,10 +12,15 @@ class GPSFixController: NSObject {
struct NotificationType {
static let ModeChanged = "GPSFixController.ModeChanged"
static let SentGPSFixes = "GPSFixController.SentGPSFixes"
}
struct UserInfo {
static let Mode = "Mode"
static let Sent = "Sent"
struct SentKey {
static let Count = "Count"
}
}
struct GPSFixSending {
@@ -129,6 +134,7 @@ class GPSFixController: NSObject {
DispatchQueue.main.async(execute: {
self.log(info: "Sending \(gpsFixes.count) GPS fixes was successful")
self.postModeChangedNotification(mode: BatteryManager.sharedManager.batterySaving ? .BatterySaving : .Online)
self.postSentGPSFixes(count: gpsFixes.count)
self.coreDataManager.deleteObjects(objects: gpsFixes)
self.coreDataManager.saveContext()
self.log(info: "\(gpsFixes.count) GPS fixes deleted")
@@ -153,9 +159,15 @@ class GPSFixController: NSObject {
fileprivate func postModeChangedNotification(mode: Mode) {
let userInfo = [UserInfo.Mode: mode.rawValue]
let notification = Notification(name: Notification.Name(rawValue: NotificationType.ModeChanged), object: self, userInfo: userInfo)
NotificationQueue.default.enqueue(notification, postingStyle: NotificationQueue.PostingStyle.asap)
NotificationQueue.default.enqueue(notification, postingStyle: .asap)
}
fileprivate func postSentGPSFixes(count: Int) {
let userInfo = [UserInfo.Sent: [UserInfo.SentKey.Count: count]]
let notification = Notification(name: Notification.Name(rawValue: NotificationType.SentGPSFixes), object: self, userInfo: userInfo)
NotificationQueue.default.enqueue(notification, postingStyle: .asap)
}
// MARK: - Properties
fileprivate lazy var checkInRequestManager: CheckInRequestManager = {
@@ -18,13 +18,39 @@ class TrainingController: NSObject {
fileprivate unowned let coreDataManager: CoreDataManager
fileprivate let trainingRequestManager: TrainingRequestManager
fileprivate var sentGPSFixesCount = 0
init(coreDataManager: CoreDataManager, baseURLString: String) {
self.coreDataManager = coreDataManager
trainingRequestManager = TrainingRequestManager(baseURLString: baseURLString)
super.init()
}
// MARK: - Notifications
fileprivate func subscribeForNotifications() {
sentGPSFixesCount = 0
NotificationCenter.default.addObserver(
self,
selector: #selector(gpsFixControllerSentGPSFixes),
name: NSNotification.Name(rawValue: GPSFixController.NotificationType.SentGPSFixes),
object: nil
)
}
fileprivate func unsubscribeFromNotifications() {
NotificationCenter.default.removeObserver(self)
}
@objc fileprivate func gpsFixControllerSentGPSFixes(_ notification: Notification) {
DispatchQueue.main.async(execute: {
guard let sentDict = notification.userInfo?[GPSFixController.UserInfo.Sent] as? [String: Any] else { return }
guard let count = sentDict[GPSFixController.UserInfo.SentKey.Count] as? NSNumber else { return }
self.sentGPSFixesCount += count.intValue
})
}
// MARK: - CreateTraining
func createTraining(
@@ -169,6 +195,7 @@ class TrainingController: NSObject {
success: @escaping () -> Void,
failure: @escaping (_ error: Error) -> Void)
{
self.unsubscribeFromNotifications()
self.stopActiveRace_SetStopTrackingTime(forTrainingRaceData: trainingRaceData, success: {
success()
}) { (error) in
@@ -228,6 +255,7 @@ class TrainingController: NSObject {
fleetName: fleetName
)
)
self.subscribeForNotifications()
}, failure: { (error, message) in
failure(error)
})
@@ -382,7 +382,43 @@ class TrainingRequestManager: NSObject {
logError(name: "\(#function)", error: error)
failure(error, stringForError(error))
}
// MARK: - LeaderboardGroups
func getRaceName(
regattaName: String,
raceName: String,
success: @escaping () -> Void,
failure: @escaping (_ error: Error, _ message: String?) -> Void)
{
let encodedRegattaName = regattaName.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
let encodedRaceName = raceName.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? ""
let urlString = "\(basePathString)/regattas/\(encodedRegattaName)/races/\(encodedRaceName)/course"
manager.get(urlString, parameters: nil, success: { (requestOperation, responseObject) in
print(responseObject)
}) { (requestOperation, error) in
print(error)
}
}
// MARK: - RegattaRaceCourse
func getRegattaRaceCourse(
regattaName: String,
raceName: String,
success: @escaping () -> Void,
failure: @escaping (_ error: Error, _ message: String?) -> Void)
{
let encodedRegattaName = regattaName.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
let encodedRaceName = raceName.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? ""
let urlString = "\(basePathString)/regattas/\(encodedRegattaName)/races/\(encodedRaceName)/course"
manager.get(urlString, parameters: nil, success: { (requestOperation, responseObject) in
print(responseObject)
}) { (requestOperation, error) in
print(error)
}
}
// MARK: - LeaderboardAutoCourse
func postLeaderboardAutoCourse(
@@ -6,6 +6,7 @@
// Copyright © 2016 com.sap.sailing. All rights reserved.
//
"NSLocationAlwaysUsageDescription" = "Um das ganze Rennen mit Deinem Gerät zu tracken, muss das Tracking auch dann fortgesetzt werden, wenn der Bildschirm abgeschaltet oder gesperrt wird. Das hilft, die Batterielaufzeit zu verlängern und versehentlich das Tracking zu stoppen.";
"NSLocationWhenInUseUsageDescription" = "Um das ganze Rennen mit Deinem Gerät zu tracken, muss das Tracking auch dann fortgesetzt werden, wenn der Bildschirm abgeschaltet oder gesperrt wird. Das hilft, die Batterielaufzeit zu verlängern und versehentlich das Tracking zu stoppen.";
"NSLocationAlwaysAndWhenInUseUsageDescription" = "Um das ganze Rennen mit Deinem Gerät zu tracken, muss das Tracking auch dann fortgesetzt werden, wenn der Bildschirm abgeschaltet oder gesperrt wird. Das hilft, die Batterielaufzeit zu verlängern und versehentlich das Tracking zu stoppen.";
"NSCameraUsageDescription" = "Die Kamera wird benötigt, um per QR-Code einen Check-In auszuführen.";
"NSPhotoLibraryUsageDescription" = "Um das Team Photo zu ersetzen, benötigt die App den Zugriff auf ihr Fotoalbum.";