-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d56aa4
commit ae443a1
Showing
1 changed file
with
64 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# CLLocationManager-Singleton-in-Swift | ||
Simply to share location services. | ||
Example Singleton class use for share location service in swift. | ||
This class will auto update location when user change current location. | ||
|
||
## Requirements | ||
* Xcode 7 or higher | ||
* Swift 2.0+ | ||
* Apple LLVM compiler | ||
* iOS 8.0 or higher | ||
* ARC | ||
|
||
## Installation | ||
* Copy LocationService.swift to your project | ||
* add the key "NSLocationAlwaysUsageDescription" to a property list(Info.plist) and set its value to some message what you want. etc. "We requires access to your phone's location bla bla bla :P" | ||
* or add the key "NSLocationWhenInUseUsageDescription" if you want to access the user's location normally while running in the foreground. | ||
|
||
|
||
## How to use - Get currentLocation singleton | ||
Call startUpdatingLocation() for start update your current location | ||
```swift | ||
LocationService.sharedInstance.startUpdatingLocation() | ||
``` | ||
Call stopUpdatingLocation() if you want to stop update your current location | ||
```swift | ||
LocationService.sharedInstance.stopUpdatingLocation() | ||
``` | ||
And if you want to get your current location just use | ||
```swift | ||
LocationService.sharedInstance.currentLocation | ||
``` | ||
|
||
## How to use - Get real time location by delegate | ||
Conform LocationServiceDelegate protocol to your view controller and don't forget import CoreLocation | ||
```swift | ||
import CoreLocation | ||
class ViewController: UIViewController, LocationServiceDelegate { | ||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
// Don't forget implement delegate | ||
LocationService.sharedInstance.delegate = self | ||
} | ||
} | ||
``` | ||
|
||
We have 2 delegation method for tracing your location and let you know if has error | ||
```swift | ||
func tracingLocation(currentLocation: CLLocation){} | ||
func tracingLocationDidFailWithError(error: NSError) {} | ||
``` | ||
## Example Appication : Tracing | ||
This example app uses location services in a potentially nonobvious way while running in the foreground or the background. | ||
You can see how to use in example application in this repository ... Good luck, Have fun :P | ||
|
||
## Contact Me | ||
|
||
Anak Mirasing | ||
|
||
- https://github.com/igroomgrim | ||
- https://www.linkedin.com/in/anakmirasing | ||
- https://twitter.com/igroomgrim | ||
- http://www.igroomgrim.com/ | ||
- [email protected] |