All Projects → irfanlone → CLLocationManager-Singleton-Swift

irfanlone / CLLocationManager-Singleton-Swift

Licence: other
No description or website provided.

Programming Languages

swift
15916 projects

Labels

Projects that are alternatives of or similar to CLLocationManager-Singleton-Swift

DI-compiler
A Custom Transformer for Typescript that enables compile-time Dependency Injection
Stars: ✭ 62 (+376.92%)
Mutual labels:  singleton
cache-all
Fast, efficient cache engines for both express routes & native nodeJs (redis, in-memory & file cache)
Stars: ✭ 22 (+69.23%)
Mutual labels:  singleton
hookleton
globalize your React Hooks without fear using the Hookleton Pattern
Stars: ✭ 39 (+200%)
Mutual labels:  singleton
hb-config
hb-config: easy to configure your python project especially Deep Learning experiments
Stars: ✭ 21 (+61.54%)
Mutual labels:  singleton
BowieCode
Personal Code/Snippet Library for Unity 3D
Stars: ✭ 23 (+76.92%)
Mutual labels:  singleton
TezAlertView
Custom singleton alertView with block completion.
Stars: ✭ 17 (+30.77%)
Mutual labels:  singleton
oh-my-design-patterns
🎨 Record the articles and code I wrote while learning design patterns
Stars: ✭ 33 (+153.85%)
Mutual labels:  singleton
Block-Breaker-Original
Arkanoid clone build as part of the Complete Unity C# Developer 2D course (http://gdev.tv/cudgithub)
Stars: ✭ 45 (+246.15%)
Mutual labels:  singleton
react-design-patterns
An attempt to implement software design patterns in React
Stars: ✭ 315 (+2323.08%)
Mutual labels:  singleton
dotnet-design-patterns-samples
The samples of .NET design patterns
Stars: ✭ 25 (+92.31%)
Mutual labels:  singleton
singleton decorator
A testable singleton decorator
Stars: ✭ 39 (+200%)
Mutual labels:  singleton
AppFacadeMVC
AppFacade For PureMVC
Stars: ✭ 13 (+0%)
Mutual labels:  singleton
tsdi
Dependency Injection container (IoC) for TypeScript
Stars: ✭ 50 (+284.62%)
Mutual labels:  singleton
design-pattern
🌴 Detail design pattern and give many demos in Java.
Stars: ✭ 28 (+115.38%)
Mutual labels:  singleton
TezActionSheet
Custom singleton actionSheet with block completion.
Stars: ✭ 18 (+38.46%)
Mutual labels:  singleton
data examples
An example app showing different ways to pass to and share data with widgets and pages.
Stars: ✭ 56 (+330.77%)
Mutual labels:  singleton
Kotlin-Singleton-Example
Example of creating Singletons with Kotlin with some MVVM architecture
Stars: ✭ 47 (+261.54%)
Mutual labels:  singleton
incache
Powerful key/value in-memory storage or on disk to persist data
Stars: ✭ 16 (+23.08%)
Mutual labels:  singleton
NYTimes-iOS
🗽 NY Times is an Minimal News 🗞 iOS app 📱 built to describe the use of SwiftSoup and CoreData with SwiftUI🔥
Stars: ✭ 152 (+1069.23%)
Mutual labels:  singleton
patterns
Good practices to create code in Java, open to other languages. ⚡
Stars: ✭ 14 (+7.69%)
Mutual labels:  singleton

CLLocationManager-Singleton-Swift

import MapKit

protocol LocationUpdateProtocol {
  func locationDidUpdateToLocation(location : CLLocation)
}

/// Notification on update of location. UserInfo contains CLLocation for key "location"
let kLocationDidChangeNotification = "LocationDidChangeNotification"

class UserLocationManager: NSObject, CLLocationManagerDelegate {

    static let SharedManager = UserLocationManager()

    private var locationManager = CLLocationManager()

    var currentLocation : CLLocation?

    var delegate : LocationUpdateProtocol!

    private override init () {
        super.init()
        self.locationManager.delegate = self
        self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
        self.locationManager.distanceFilter = kCLLocationAccuracyHundredMeters
        locationManager.requestAlwaysAuthorization()
        self.locationManager.startUpdatingLocation()
    }

    // MARK: - CLLocationManagerDelegate

    func locationManager(manager: CLLocationManager, didUpdateToLocation newLocation: CLLocation, fromLocation oldLocation: CLLocation) {
        currentLocation = newLocation
        let userInfo : NSDictionary = ["location" : currentLocation!]

        dispatch_async(dispatch_get_main_queue()) { () -> Void in
            self.delegate.locationDidUpdateToLocation(self.currentLocation!)
            NSNotificationCenter.defaultCenter().postNotificationName(kLocationDidChangeNotification, object: self, userInfo: userInfo as [NSObject : AnyObject])
        }
    }

}

##Usage:

In your view-controller, do the initialization

  let LocationMgr = UserLocationManager.SharedManager
  LocationMgr.delegate = self

Implement the proctocol - LocationUpdateProtocol

// MARK: - LocationUpdateProtocol
func locationDidUpdateToLocation(location: CLLocation) {
    currentLocation = location
    print(currentLocation)
}

or you can choose to receive the notifications

NSNotificationCenter.defaultCenter().addObserver(self, selector: "locationUpdateNotification:", name: kLocationDidChangeNotification, object: nil)

Also add the following Keys to your info.plist

NSLocationAlwaysUsageDescription
NSLocationWhenInUseUsageDescription

#Contribution:

Any contribution is welcome. Just submit a pull request.

#Copyright and License The source code is released under the MIT License (MIT).

Copyright (c) 2016 Irfan Lone

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].