forked from hyperoslo/ImagePicker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request hyperoslo#128 from aashishdhawan/refactor/location…
…-manager Refactored LocationManager into its own File
- Loading branch information
Showing
3 changed files
with
41 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
/* Begin PBXBuildFile section */ | ||
39D134101CAC4B4E00EA2ECE /* AssetManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39D1340F1CAC4B4E00EA2ECE /* AssetManager.swift */; }; | ||
39E3C3311CAFD79200340DAD /* LocationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39E3C3301CAFD79200340DAD /* LocationManager.swift */; }; | ||
D5D370C01C44FD1600690C0A /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = D5D370BA1C44FD1600690C0A /* [email protected] */; }; | ||
D5D370C11C44FD1600690C0A /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = D5D370BB1C44FD1600690C0A /* [email protected] */; }; | ||
D5D370C21C44FD1600690C0A /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = D5D370BC1C44FD1600690C0A /* [email protected] */; }; | ||
|
@@ -43,6 +44,7 @@ | |
|
||
/* Begin PBXFileReference section */ | ||
39D1340F1CAC4B4E00EA2ECE /* AssetManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssetManager.swift; sourceTree = "<group>"; }; | ||
39E3C3301CAFD79200340DAD /* LocationManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocationManager.swift; sourceTree = "<group>"; }; | ||
D5D370BA1C44FD1600690C0A /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; }; | ||
D5D370BB1C44FD1600690C0A /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; }; | ||
D5D370BC1C44FD1600690C0A /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; }; | ||
|
@@ -152,6 +154,7 @@ | |
D5DC59BB1C201CC4003BD79B /* Photos.swift */, | ||
D5DC59BC1C201CC4003BD79B /* TopView */, | ||
39D1340F1CAC4B4E00EA2ECE /* AssetManager.swift */, | ||
39E3C3301CAFD79200340DAD /* LocationManager.swift */, | ||
); | ||
path = Source; | ||
sourceTree = "<group>"; | ||
|
@@ -316,6 +319,7 @@ | |
files = ( | ||
D5DC59CE1C201CC4003BD79B /* TopView.swift in Sources */, | ||
D5DC59C41C201CC4003BD79B /* ImageStack.swift in Sources */, | ||
39E3C3311CAFD79200340DAD /* LocationManager.swift in Sources */, | ||
D5DC59CB1C201CC4003BD79B /* ImageGalleryViewDataSource.swift in Sources */, | ||
D5DC59CA1C201CC4003BD79B /* ImageGalleryViewCell.swift in Sources */, | ||
D5DC59C81C201CC4003BD79B /* ConstraintsSetup.swift in Sources */, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Foundation | ||
import CoreLocation | ||
|
||
class LocationManager: NSObject, CLLocationManagerDelegate { | ||
var locationManager = CLLocationManager() | ||
var latestLocation: CLLocation? | ||
|
||
override init() { | ||
super.init() | ||
locationManager.delegate = self | ||
locationManager.desiredAccuracy = kCLLocationAccuracyBest | ||
locationManager.requestWhenInUseAuthorization() | ||
} | ||
|
||
func startUpdatingLocation() { | ||
locationManager.startUpdatingLocation() | ||
} | ||
|
||
func stopUpdatingLocation() { | ||
locationManager.stopUpdatingLocation() | ||
} | ||
|
||
// MARK: - CLLocationManagerDelegate | ||
|
||
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { | ||
// Pick the location with best (= smallest value) horizontal accuracy | ||
latestLocation = locations.sort{ $0.horizontalAccuracy < $1.horizontalAccuracy }.first | ||
} | ||
|
||
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) { | ||
if status == .AuthorizedAlways || status == .AuthorizedWhenInUse { | ||
locationManager.startUpdatingLocation() | ||
} else { | ||
locationManager.stopUpdatingLocation() | ||
} | ||
} | ||
} |