malcommac / swiftlocation Goto Github PK
View Code? Open in Web Editor NEW⚓️ Async/Await CLLocationManager Wrapper for Apple Platforms
License: MIT License
⚓️ Async/Await CLLocationManager Wrapper for Apple Platforms
License: MIT License
Waiting for Xcode 8 support.
CocoaPods/CocoaPods#5825
You can still download using:
pod 'SwiftLocation', :git => 'https://github.com/malcommac/SwiftLocation.git', :branch => 'master'
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 !?
hi,
the beaconRequest state is never set. only in stopMonitoring and then it is pointless.
hi,
beaconManager stopMonitoring isn't really implemented. it doesn't stop the cllocationmanager for example
Unable to build project example...
Hey, could you add support for watchOS 2?
"platforms": {
"iOS": "8.0",
"watchos": "2.0"
}
More info: https://medium.com/@JTEhlert/using-cocoapods-with-watchos-2-723b92eae04f
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
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)
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.
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:
I would be great I you add a opportunity for watching for auth status changes using closures.
When try to install You pods, I receive an error "[!] [!] The Podfile does not contain any dependencies."
public func cancelRequest(identifier: Int) -> Bool
{
if let request = request(identifier) as SwiftLocationRequest! {
request.markAsCancelled(nil)
return true // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< insert this line
}
return false
}
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.
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.
Each time I try to get location using currentLocation I get a timeout error. With currentLocation I get nothing, neither onSuccess or onFail are called.
Is it supposed to work or it's still in development?
When i update cocoapods to version 0.9.0 SwiftLocation.shared stopped working.
if you choose location accuracy house or room you get no responses...
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)")
}
}`
https://ip-api.com/json - the website that you use - is down, so it is impossible to use Accuracy.Country anymore.
Hi,
I discovered monitoring for ble beacons will never work as the callbacks filter based monitoredGeoRegions I fixed it by doubling the code for now ;) .. there should be a common protocol
Maybe should to make public last location in LocationManager?
SwiftLocation.shared.continuousLocation(Accuracy.Room ...) rarely calls the onSuccess closure. App will be suspended after a while. Tested with iOS 8.3.
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?
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!
I copy the swift file directly to project , and I got the error,why?
Hi!
You are plan add new param for iOS 9 allowsBackgroundLocationUpdates ?
https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/occ/instp/CLLocationManager/allowsBackgroundLocationUpdates
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.
Hello.
Nice library !
Does this work without the user to "Allow" taking his location?
Hi, thank you for beautiful lib. If there an option if I need to get array of nearby addresses/places?
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
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.
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
Why when I call .cancelRequest (pass request ID), fires error callback in .continuousLocation ?
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.
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.
It seems that SwiftLocation.shared.currentLocation
returns a CLLocation
object and not a CLPlacemark
object as the documentation states.
swift 2 is now released. You can read here: https://developer.apple.com/swift/blog/
Maybe move branch to master now?
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.
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()
}
}
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 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
I want to provide my own api key to your library and there is no option for that .
Fixed via PR. #54
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
}
No location update when use .continuousLocation and Accuracy.Room. When use Accuracy.House work fine.
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.
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:
RegionHandlerStateDidChange
, RegionHandlerStateDidChange
, RegionHandlerError
, ...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. 😖
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)")
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.