Giter Site home page Giter Site logo

malcommac / swiftlocation Goto Github PK

View Code? Open in Web Editor NEW
3.4K 90.0 430.0 7.92 MB

⚓️ Async/Await CLLocationManager Wrapper for Apple Platforms

License: MIT License

Swift 99.53% Shell 0.47%
location-services cllocationmanager swift-library locationtracking swift swiftlang

swiftlocation's People

Contributors

abakhtin avatar ahalls avatar andreabusi avatar appfrilans avatar asidden avatar ay8s avatar bogdan-razvan avatar cyupa avatar dev4jam avatar dharin-shah avatar evermeer avatar fleitz avatar gauravmnit07 avatar grangej avatar hamzaozturk avatar itruf avatar jerometonnelier avatar jonasrottmann avatar kronik avatar lm2s avatar malcommac avatar mimo42 avatar phongleq avatar qasimsina avatar rajeshkp avatar reprotector avatar stephenwoodford avatar terwanerik avatar wendellxy avatar ysoftware avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swiftlocation's Issues

monitorForBeaconFamily / monitorForBeacon -> Crashes with nil exception :: The initializers for the BeaconRequest object seem broken to me?!

Hi
monitorForBeaconFamily / monitorForBeacon -> Crashes with nil exception

The initializers for the BeaconRequest object seem broken to me?!
BECAUSE :: they use beaconRegion before assigning it...

see:

 self.beaconRegion = CLBeaconRegion(proximityUUID: NSUUID(UUIDString: self.UUID)!, identifier: self.identifier)

self.UUID uses the region before it is even assigned:

 return beaconRegion!.proximityUUID.UUIDString

IMHO this is broken and maybe a typo. self.UUID should be uuid !?

monitorRegion onEnter not called

Great project. It is my favourite Core Location wrapper!

In my project, monitorRegion onEnter is not getting called.

var region = CLCircularRegion(center: regionCoordinates, radius: CLLocationDistance(50), identifier: "identifier_region") let requestID = SwiftLocation.shared.monitorRegion(region, onEnter: { (region) -> Void in // events called on enter }) { (region) -> Void in // event called on exit }

Even though locationManager(manager: CLLocationManager, didEnterRegion region: CLRegion) is called in SwiftLocation. What have I missed?

Thanks
Martin

Runtime error - EXC_BAD_ACCESS with Mapbox-iOS-SDK Info.plist change

Ran across what seems like a conflict in Info.plist when using Cocoapods - SwiftLocation and Mapbox-iOS-SDK.

platform :ios, '8.0'
use_frameworks!

target 'swiftLocationTest' do
    pod 'SwiftLocation', '~> 0.2'
    pod 'Mapbox-iOS-SDK', '~> 3.0'
end

Recreate (in simulator)

  • Create new project
  • Create pod and add SwiftLocation
  • Update pod, build+run everything works
  • Add Mapbox-iOS-SDK
  • Update pod, build+run everything works
  • Setup Mapbox
    • add mapbox provided Settings.bundle file and update Info.plist with access token
  • Update pod, build+run error (see below)

screen shot 2015-12-02 at 8 56 59 pm

Believed cause
Mapbox access key name conflict with SwiftLocation for Info.plist ( Key: MGLMapboxAccessToken )

Did some messing around and my test app works when the individual pods are installed (comment out SwiftLocation or Mapbox) and with different pods installed (SwiftLocation + another pod besides Mapbox). But once you have SwiftLocation and Mapbox together and add the mapbox plist edits, it breaks.

You can edit the plist with any variation of the required Key ( MGLMapboxAccessT or MGLMapboxToken or etc etc ) and build+run works. So I'm guessing some type of naming conflict somewhere and out of the two projects I'm betting you would care more to try to fix it.

screen shot 2015-12-02 at 9 19 12 pm

Beacons Monitoring Service Errors

There are several errors related to beacon monitoring services.
I've taken some time to rewrite the entire class and align it with the Location services infrastructure.
This is a work in progress which will take some days (new version is currently on develop branch).

This post group the following errors:

  • #58 beaconManager stopMonitoring isn't really implemented. it doesn't stop the cllocationmanager for example
  • #57 beaconRequest state never set
  • #56 monitoring for ble beacons will never work as the callbacks filter based monitoredGeoRegions
  • #52 monitorForBeaconFamily / monitorForBeacon -> Crashes with nil exception :: The initializers for the BeaconRequest object seem broken to me?!

cancelRequest never returns true

public func cancelRequest(identifier: Int) -> Bool
{
if let request = request(identifier) as SwiftLocationRequest! {
request.markAsCancelled(nil)
return true // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< insert this line
}
return false
}

iOS 9 Background location

I don't seen any usage of allowsBackgroundLocationUpdates of CLLocationManager in you library.

Since iOS 9 you need to set allowsBackgroundLocationUpdates = true to allow location updates while app in background mode.

get user location as first thing

Hello

i'm trying to get user's location in viewDidLoad using this closure :

   var userLocation = CLLocation()
        Location.getLocation(withAccuracy:  .IPScan, onSuccess: { (location) in
            // approximate location is here
             userLocation = location

        }) { (lastValidLocation, error) in
            // something wrong has occurred; error will tell you what
        }

but I found out that the userLocation is (0.00,0.00)

how to solve this problem without implementing CLLocation methods ?

thanks.

Infinite loop if location disabled

I'm using the observeLocations method but if the user switched the location of my app to "never" the method starts in infinite loop.

Here you have the stack trace:
screen shot 2016-05-25 at 17 39 01

If the location services are granted for my app (Always) it works perfectly but if they are turned off (Never) it crashes.

Update to 0.9.0

When i update cocoapods to version 0.9.0 SwiftLocation.shared stopped working.

Always Timeout on iPod and iPhone 6

currentLocation always timeout on iPod and iPhone 6,and app will crash when timeout
here my code:
` func updateLocation(errorHandler : (ErrorType -> Void)?){

    SwiftLocation.shared.cancelAllRequests()
    do{
        try SwiftLocation.shared.currentLocation(.Room, timeout: 10.0, onSuccess: {
            if let location = $0{
                self.reverseLocation(location)
            }
            }, onFail: { error in
                self.getSignificantLocation(errorHandler)
        })
    }catch(let error){
        print("Error \(error)")
    }

}`

Last Location

Maybe should to make public last location in LocationManager?

Doesn't update heading continuously

I faced a problem to try observe my device's heading.

When I used belove method to observe heading. I couldn't get the heading continuously. onSuccess closure triggered rarely.
LocationManager.shared.observeHeading(onSuccess: onSuccess, onError: onError)

I looked up the codes I have seen this if condition.

if self.validateHeading(heading!) == true { self.lastHeading = heading self.onSuccess?(self.lastHeading!) }

When I deleted the if condition, the code works well.
What is the purpose of this code?

Significant Location : Only the first update is received

Hi, I've checked in your code that when you call:

completeRequest(request: SwiftLocationRequest!, object: AnyObject?, error: NSError?)

and then you check the request type:

if cRequest.isCancelled == true || cRequest.type != RequestType.ContinuousLocationUpdate) {
    self.requests.removeAtIndex(idx)
}

This is removing any requests different from ContinuousLocationUpdate, including ContinuousSignificantLocation. This causes that only the first location update is processed in the callback when you use significant location method. The solution is that simple:

if cRequest.isCancelled == true || (cRequest.type != RequestType.ContinuousLocationUpdate && cRequest.type != RequestType.ContinuousSignificantLocation)  {
    self.requests.removeAtIndex(idx)
}

Thanks for your time.
Great job!

Support for Carthage

Because of some legacy static lib issues, we're using Cocoapods only for Objective-C modules and Carthage for Swift modules. It would be really great if we could use SwiftLocation via Cocoapods.

Newbie question

Hello.
Nice library !
Does this work without the user to "Allow" taking his location?

timeout

Sorry if this is a bit amateur but does anyone know how to set the timeout in version 0.9? The documentation stated that LocationRequest also specify a timeoutTimer property you can set to abort the request itself if no valid data is received in a certain amount of time. By default it's disabled.
But XCode tells me that LocationRequest has no member timeoutTimer

.IPScan accuracy needs NSAppTransportSecurity

The URL call for .IPScan points to an http address which is prohibited by default. We should enable such calls in the app to be able to call the API and get the results.

I'll make a PR to point this out in the README file.

Not working on iOS 10 beta

Hello and thank you for your great work!

I'm using the provided latest version of the sources and I'm encountering an error on a device running iOS 10 beta 6 in Xcode 7 using Swift 2.2.

Here's my test project, maybe you could tell me what's wrong.

Works perfectly fine on iOS 9.3.5

I always have timeout error callback called after the location search success

I run Location like this :

let request: SwiftLocation.Request = SwiftLocation.Location.getLocation(withAccuracy: .Block, frequency: .ByDistanceIntervals(meters: 100), timeout: 10, onSuccess: { (location) in
    debugPrint(NSDate().timeIntervalSince1970 * 1000, "Location acquired")
}) { (lastValidLocation, error) in
    debugPrint(NSDate().timeIntervalSince1970 * 1000, "Location error", error._code, error.description)
}
print("Start location request \(request!.UUID)\n")
request.start()

and both events are triggered :

Start location request DEBCACED-1C5E-4E0D-B7E0-3DB9D273C9DA

1471859016543.7268 "Location acquired"
1471859026548.197 "Location error" 1 "Timeout for request"

So transaction is canceled and then no further location change triggers the action.

does not handle authorization correctly

Run this snippet, then decline on the location authorization:

Location.getLocation(withAccuracy: .Block, onSuccess: { foundLocation in
}) { (lastValidLocation, error) in
}

you will get back an error saying Authorization did change.

Run it again and neither closure is called. So no "onSuccess" and no error.

That is quite broken.

Accessing Placemark Attributes

Should this work? I'm trying to get the state/province from the placemark.

    let coordinates = CLLocationCoordinate2DMake(lat, long)
            SwiftLocation.shared.reverseCoordinates(Service.Apple, coordinates: coordinates, onSuccess: { (place) -> Void in

                print(place!.administrativeArea)
                }, onFail: { (error) in
                    print(error)
            })

Edit: So it turns out some of the attributes are accessible.
print(place.country) works, but for some reason print(place.administrativeArea) doesn't work, even though it's showing up when I simply try print(place). I'm in Canada, but I thought CLPlacemark was supposed to work for Canada.

Swift 2.3 Syntax issues

SwiftLocation/src/BeaconManager.swift:214:23: Binary operator '==' cannot be applied to operands of type 'CBManagerState' and 'CBPeripheralManagerState'
@objc public func peripheralManagerDidUpdateState(peripheral: CBPeripheralManager) {
        if peripheral.state == CBPeripheralManagerState.PoweredOn {
            self.broadcastedBeacons.forEach({ beacon in
                peripheral.startAdvertising(beacon.dataToAdvertise())
            })
        } else {
            self.cleanUpAllAdvertisers()
        }
    }

currentLocation always goes timeout

Hi,
It was working fine in the simulator, but now it always goes timeout and returns error. Either in device or simulator. (I am not sure if that is relevant but there is no sim card in device)

here is the code:

try! SwiftLocation.shared.currentLocation(.Room, timeout: 60.0, onSuccess: { (location) -> Void in
                postRequest(.UPDATE_LOCATION, additionalParameters: ["\(location?.coordinate.latitude)","\(location?.coordinate.longitude)"], onSuccess: { (json) -> () in
                        print(">>>location_successfully_updated")
                    }, onFailure: { (errorCode) -> () in
                    print(">>>couldn't_update_location")
                })
                }, onFail: { (error) -> Void in
                    print(">>>couldn't_get_location")
                    print(error?.localizedDescription)
            })

and the output:

Optional(Error Domain=NSCocoaErrorDomain Code=0 "Timeout reached" UserInfo={NSLocalizedDescription=Timeout reached})

Question: How to get currency location of another device

@malcommac

Question, How could I use SwiftLocation for this scenario (I will user Uber as an example)

Driver is delegated to capture a charge (Charge Rider's credit card) at the end of a trip.
The action can only happen if Rider is within Room distance (Or an arbitrary distance i set).
Else ERROR: Rider is not within distance

How can use swift location to so Driver can get Rider's current location when Rider's device is either in Foreground or Background

Location services does not start correctly

First into the application without authorization, or executing a method
info.plist config:NSLocationWhenInUseUsageDescription

Location.getLocation(withAccuracy: .Block, onSuccess: { foundLocation in

})  { (lastValidLocation, error) in
           // something bad has occurred
           // - error contains the error occurred
          // - lastValidLocation is the last found location (if any) regardless specified accuracy level
 }

Using the name 'Location' ?

Why did you change the name with a generic term 'Location' ?
It cause lots of conflict with other frameworks, classes etc...
You can use a unique name.

Swift 3 build errors

I am trying out this framework for my future project (it looks great), but unfortunately the test project I have started (Using Cocoapods (1.1.0.beta 1) with:

pod 'SwiftLocation' :git: => 'https://github.com/malcommac/SwiftLocation.git', :branch => 'feature/swift3'

doesn't build. There is two different type of errors and 15 errors overall:

  1. Some declarations are missing, among them are: RegionHandlerStateDidChange, RegionHandlerStateDidChange, RegionHandlerError, ...
  2. Beacon has two declarations. One in BeaconManager.swift and the other one in Common.swift

I'm guessing you are testing and building your project without the pods (have you used pod lib create ...?) This is always error prone.

Could you take a look. I'm lost a bit. There are files in my pod that have not been added to your test project. 😖

Request can receive events about location service auth status change

Each request should be able to receive notifications about CLLocationManager's authorization change events.
So each Request will implements a new handler called .onAuthDidChange() you can implement to receive the new status.
Example:

let request = Location.getLocation(withAccuracy: .City, frequency: .Continuous, timeout: nil, onSuccess: { (loc) in
    // get location
}) { (last, err) in
    // error
}

// Receive notifications about Auth Status Changes
request.onAuthDidChange = { newStatus in
    print("New CLLocationManager's auth status is=\(newStatus)")
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.