class Locman::Manager
This wraps CLLocationManager in more Ruby way.
Constants
- ACCURACY_MAP
@!visibility private
- AUTHORIZED_CONSTS
@!visibility private
- NOT_AUTHORIZED_CONSTS
@!visibility private
Attributes
@return [Symbol] Desired accuracy of the location data.
@return [Boolean] Set whether location should be updated in the background or not.
@return [Integer] The minimum horizontal distance threshold for on_update
event.
@return [Proc] Proc function that will be called when there is an error while retrieving the location.
@return [Proc] Proc function that will be called when there is a new location retrieval.
@return [Proc] Proc function that will be called when there is a new visit event.
Public Class Methods
Creates a new Locman::Location
instance. @param options [Hash] Attributes that will be assigned on instance creation @return [Locman::Manager]
# File lib/locman/manager.rb, line 49 def initialize(params = {}) params.each { |key, value| send("#{key}=", value) } @accuracy ||= :best @distance_filter ||= 0 self end
Public Instance Methods
Sets a desired accuracy. @param accuracy [Symbol] Desired accuracy of the location data.
# File lib/locman/manager.rb, line 60 def accuracy=(accuracy) fail(ArgumentError, "Invalid accuracy: #{accuracy}") if ACCURACY_MAP[accuracy].nil? manager.desiredAccuracy = ACCURACY_MAP[accuracy] @accuracy = accuracy end
Sets whether location should be updated on the background or not.
# File lib/locman/manager.rb, line 73 def background=(background) if !background.is_a?(TrueClass) && !background.is_a?(FalseClass) fail(ArgumentError, "Background should be boolean") end manager.allowsBackgroundLocationUpdates = background @background = background end
# File lib/locman/manager.rb, line 66 def distance_filter=(distance_filter) fail(ArgumentError, "Distance filter should be integer") unless distance_filter.is_a?(Integer) manager.distanceFilter = distance_filter @distance_filter = distance_filter end
Delegates
# File lib/locman/manager.rb, line 149 def locationManager(manager, didChangeAuthorizationStatus: status) @after_authorize.call(authorized?(status)) unless @after_authorize.nil? end
# File lib/locman/manager.rb, line 92 def on_error=(on_error) fail(ArgumentError, "Must provide proc") unless on_error.is_a?(Proc) @on_error = on_error end
# File lib/locman/manager.rb, line 87 def on_update=(on_update) fail(ArgumentError, "Must provide proc") unless on_update.is_a?(Proc) @on_update = on_update end
# File lib/locman/manager.rb, line 97 def on_visit=(on_visit) fail(ArgumentError, "Must provide proc") unless on_visit.is_a?(Proc) @on_visit = on_visit end
# File lib/locman/manager.rb, line 127 def stop_update! manager.stopUpdatingLocation end
# File lib/locman/manager.rb, line 135 def stop_update_significant! manager.stopMonitoringSignificantLocationChanges end
# File lib/locman/manager.rb, line 143 def stop_update_visits! manager.stopMonitoringVisits end
# File lib/locman/manager.rb, line 119 def update! if CLLocationManager.authorizationStatus != KCLAuthorizationStatusAuthorized fail(Exception, "Location permission is not authorized by user") end manager.startUpdatingLocation end
# File lib/locman/manager.rb, line 131 def update_significant! manager.startMonitoringSignificantLocationChanges end
# File lib/locman/manager.rb, line 139 def update_visits! manager.startMonitoringVisits end
Private Instance Methods
# File lib/locman/manager.rb, line 173 def manager @manager ||= begin manager = CLLocationManager.new manager.delegate = self manager end end