Skip to content

Commit

Permalink
Support resuming region monitoring after termination
Browse files Browse the repository at this point in the history
  • Loading branch information
robbiet480 committed Apr 23, 2017
1 parent 4572c0e commit ebe4ed3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions HomeAssistant/AppDelegate.swift
Expand Up @@ -37,6 +37,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
print("Realm file path", Realm.Configuration.defaultConfiguration.fileURL!.path)
Fabric.with([Crashlytics.self])

if launchOptions?[UIApplicationLaunchOptionsKey.location] != nil {
resumeRegionMonitoring()
}

UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum)

NetworkActivityIndicatorManager.shared.isEnabled = true
Expand Down Expand Up @@ -270,6 +274,19 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}

func resumeRegionMonitoring() {
if HomeAssistantAPI.sharedInstance.locationEnabled {
if HomeAssistantAPI.sharedInstance.Configured == false {
if let baseURL = keychain["baseURL"], let apiPass = keychain["apiPassword"] {
HomeAssistantAPI.sharedInstance.Setup(baseURL: baseURL, password: apiPass,
deviceID: keychain["deviceID"])
}
}

HomeAssistantAPI.sharedInstance.beaconManager.resumeScanning()
}
}

}

@available(iOS 10, *)
Expand Down
4 changes: 4 additions & 0 deletions HomeAssistant/HAAPI.swift
Expand Up @@ -1245,6 +1245,10 @@ class BeaconManager: NSObject, CLLocationManagerDelegate {
}
}

func resumeScanning() {
print("Resuming scanning of \(locationManager.monitoredRegions.count) regions!")
}

}

enum LocationUpdateTypes {
Expand Down

0 comments on commit ebe4ed3

Please sign in to comment.