Skip to content

Commit

Permalink
Submit a oneshot location during background fetch only if location is…
Browse files Browse the repository at this point in the history
… enabled, otherwise do a simple device identify
  • Loading branch information
robbiet480 committed Apr 21, 2017
1 parent 9091df6 commit abe1d5e
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions HomeAssistant/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,26 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
deviceID: keychain["deviceID"])
}
}
HomeAssistantAPI.sharedInstance.sendOneshotLocation().then { success -> Void in
if success == true {
if HomeAssistantAPI.sharedInstance.locationEnabled {
HomeAssistantAPI.sharedInstance.sendOneshotLocation().then { success -> Void in
if success == true {
completionHandler(UIBackgroundFetchResult.newData)
} else {
completionHandler(UIBackgroundFetchResult.failed)
}
}.catch {error in
print("Error when attempting to submit location update during background fetch")
Crashlytics.sharedInstance().recordError(error)
completionHandler(UIBackgroundFetchResult.failed)
}
} else {
HomeAssistantAPI.sharedInstance.identifyDevice().then { _ -> Void in
completionHandler(UIBackgroundFetchResult.newData)
} else {
}.catch {error in
print("Error when attempting to identify device during background fetch")
Crashlytics.sharedInstance().recordError(error)
completionHandler(UIBackgroundFetchResult.failed)
}
}.catch {error in
print("Error when attempting to submit location update")
Crashlytics.sharedInstance().recordError(error)
completionHandler(UIBackgroundFetchResult.failed)
}
}

Expand Down

0 comments on commit abe1d5e

Please sign in to comment.