{"id":19805607,"url":"https://github.com/remirobert/corelocationprovider","last_synced_at":"2025-05-01T06:31:21.465Z","repository":{"id":56906665,"uuid":"119243003","full_name":"remirobert/CoreLocationProvider","owner":"remirobert","description":"CoreLocation subscription provider.","archived":false,"fork":false,"pushed_at":"2019-04-22T02:34:29.000Z","size":25,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-19T12:49:42.238Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/remirobert.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-28T09:00:33.000Z","updated_at":"2019-04-23T01:23:59.000Z","dependencies_parsed_at":"2022-08-20T19:50:26.024Z","dependency_job_id":null,"html_url":"https://github.com/remirobert/CoreLocationProvider","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remirobert%2FCoreLocationProvider","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remirobert%2FCoreLocationProvider/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remirobert%2FCoreLocationProvider/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remirobert%2FCoreLocationProvider/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/remirobert","download_url":"https://codeload.github.com/remirobert/CoreLocationProvider/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224246064,"owners_count":17279649,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T09:04:39.917Z","updated_at":"2024-11-12T09:04:40.567Z","avatar_url":"https://github.com/remirobert.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CoreLocationProvider\n\n[![Build Status](https://app.bitrise.io/app/cb18c1f8eef859c0/status.svg?token=sy_NvUGoqs4gi8PyViB_Ng)](https://app.bitrise.io/app/cb18c1f8eef859c0/status.svg?token=sy_NvUGoqs4gi8PyViB_Ng)\n[![codecov](https://codecov.io/gh/remirobert/CoreLocationProvider/branch/master/graph/badge.svg)](https://codecov.io/gh/remirobert/CoreLocationProvider)\n\nA centralized location update subscription for you app.\nCoreLocationProvider is a wrapper around CoreLocation's CLLocationManager giving you a centralized place to manage location updates in your app. Uses a list of subscriber to forwards the data back.\n\n## Installation\n\nTo add CoreLocationProvider to your app, simply add **CoreLocationProvider** to your ```Podfile```.\n\n```\ntarget 'MyApp' do\n  use_frameworks!\n  pod 'CoreLocationProvider'\nend\n```\n\n## Location Authorization Status\n\nCoreLocationProvider can manage the location authorization status of your app. You can subscribe to it, to be informed when the authorization status is updated.\n\n```swift\nclass SettingsViewController: UIViewController {\n    override func viewDidLoad() {\n        super.viewDidLoad()\n        CoreLocationProvider.shared.subscribePermissionUpdate(object: self)\n        if CoreLocationProvider.shared.currentPermissionStatus != .authorizedWhenInUse {\n            CoreLocationProvider.shared.requestForAuthorization(type: LocationPermissionType.whenInUseAuthorization)\n        }\n    }\n}\n\nextension SettingsViewController: CoreLocationPermissionDelegate {\n    func didUpdateAuthorization(status: CLAuthorizationStatus) {\n        print(\"status : \\(status)\")\n    }\n}\n```\n\nThe CoreLocationProvider is conform to the protocol CoreLocationPermissionChecker. The role of this protocol is to provide an interface to handle the localization authorization status only. So, in your app, you can inject that small protocol, without using the whole CoreLocationProvider, and let you the possibility to mock that instance.\n\n```swift\nclass SettingsViewModel {\n    private let locationPermissionChecker: CoreLocationPermissionChecker\n\n    init(locationPermissionChecker: CoreLocationPermissionChecker = CoreLocationProvider.shared) {\n        self.locationPermissionChecker = locationPermissionChecker\n    }\n}\n```\n\n## Location updates\n\nIf your class is interested in getting location updates, it should implement the CoreLocationProviderDelegate protocol.\nYou need to start listening for update with **startListening**, or **startListeningSingleUpdate** for a single location.\n\n```Swift\nclass ViewController: UIViewController {\n    override func viewDidLoad() {\n        super.viewDidLoad()\n        CoreLocationProvider.shared.subscribeLocationUpdate(object: self)\n        CoreLocationProvider.shared.startListening()\n    }\n}\n\nextension ViewController: CoreLocationProviderDelegate {\n    func didUpdateLocation(location: CLLocation) {\n        print(\"get new location point : \\(location)\")\n    }\n\n    func didFailGettingLocation(error: Error) {\n        print(\"get error : \\(error.localizedDescription)\")\n    }\n}\n```\n\nYou can access to the last known location: \n```Swift\nCoreLocationProvider.shared.lastKnownLocation\n```\n\n## Subscription\n\nYou can subscribe to the the location updates / permission in different places of your app. You can remove a subscription or all of them by calling the appropriete function.\n\nNote that the subscription will be automaticcaly unsubbscribed when the object will be release. So you don't need to unsubscribe manually, or if you want to stop receiving updates.\n\n```Swift\nCoreLocationProvider.shared.subscribeLocationUpdate(object: self)\nCoreLocationProvider.shared.unsubscribeLocationUpdate(object: self)\nCoreLocationProvider.shared.unsubscribeAllLocationUpdate()\n\nCoreLocationProvider.shared.subscribePermissionUpdate(object: self)\nCoreLocationProvider.shared.unsubscribePermissionUpdate(object: self)\nCoreLocationProvider.shared.unsubscribeAllPermissionUpdate()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fremirobert%2Fcorelocationprovider","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fremirobert%2Fcorelocationprovider","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fremirobert%2Fcorelocationprovider/lists"}