Skip to content

Commit

Permalink
Merge branch 'release/1.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
malcommac committed Nov 30, 2016
2 parents 07fbd20 + 3039f8f commit 8df37c3
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 55 deletions.
28 changes: 27 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
.DS_Store
# Created by https://www.gitignore.io/api/xcode

### Xcode ###
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Location.getLocation(withAccuracy: .Block, frequency: .OneShot, timeout: 50, onS
}) { (lastValidLocation, error) in
}
// Sometimes in the future
request.stop() // Stop receiving updates
request.cancel() // Stop receiving updates
request.pause() // Temporary pause events
request.start() // Restart a paused request
```
Expand Down Expand Up @@ -291,7 +291,7 @@ Keep in mind: advertising not works in background.
let request = Beacons.advertise(beaconName: "name", UUID: proximity, major: major, minor: minor, powerRSSI: 4, serviceUUIDs: [])
```

Use ```stop()``` on ```request``` to stop beacon advertise.
Use ```cancel()``` on ```request``` to stop beacon advertise.

([Documentation ↑](#documentation))

Expand Down
2 changes: 1 addition & 1 deletion SwiftLocation.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'SwiftLocation'
s.version = '1.1.0'
s.version = '1.1.1'
s.license = 'MIT'
s.summary = 'Elegant Location Services and Beacon Monitoring in Swift'
s.homepage = 'https://github.com/malcommac/SwiftLocation'
Expand Down
16 changes: 8 additions & 8 deletions SwiftLocation/SwiftLocation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@
08819F241CD51F9B00EFD938 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
08819F2F1CD51FA700EFD938 /* Commons.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Commons.swift; path = ../../src/Commons.swift; sourceTree = "<group>"; };
08819F301CD51FA700EFD938 /* HeadingRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = HeadingRequest.swift; path = ../../src/HeadingRequest.swift; sourceTree = "<group>"; };
08819F311CD51FA700EFD938 /* LocationManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LocationManager.swift; path = ../../src/LocationManager.swift; sourceTree = "<group>"; };
08819F311CD51FA700EFD938 /* LocationManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; name = LocationManager.swift; path = ../../src/LocationManager.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
08819F321CD51FA700EFD938 /* LocationRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LocationRequest.swift; path = ../../src/LocationRequest.swift; sourceTree = "<group>"; };
08819F341CD51FA700EFD938 /* VisitRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = VisitRequest.swift; path = ../../src/VisitRequest.swift; sourceTree = "<group>"; };
210301201D6CA7BE00A0A38C /* BeaconsManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BeaconsManager.swift; path = ../../src/BeaconsManager.swift; sourceTree = "<group>"; };
210301201D6CA7BE00A0A38C /* BeaconsManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; name = BeaconsManager.swift; path = ../../src/BeaconsManager.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
210301221D6CBEF100A0A38C /* GeoRegionRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = GeoRegionRequest.swift; path = ../../src/GeoRegionRequest.swift; sourceTree = "<group>"; };
210301241D6CD22F00A0A38C /* BeaconRegionRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BeaconRegionRequest.swift; path = ../../src/BeaconRegionRequest.swift; sourceTree = "<group>"; };
210301261D6CDD2B00A0A38C /* BeaconAdvertiseRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BeaconAdvertiseRequest.swift; path = ../../src/BeaconAdvertiseRequest.swift; sourceTree = "<group>"; };
210301261D6CDD2B00A0A38C /* BeaconAdvertiseRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; name = BeaconAdvertiseRequest.swift; path = ../../src/BeaconAdvertiseRequest.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
213F85081D61C7FC00835DCA /* SwiftLocationDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SwiftLocationDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
213F850A1D61C7FC00835DCA /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
213F850C1D61C7FC00835DCA /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -263,7 +263,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0800;
LastUpgradeCheck = 0810;
ORGANIZATIONNAME = danielemargutti;
TargetAttributes = {
08819F121CD51F9B00EFD938 = {
Expand Down Expand Up @@ -437,7 +437,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -483,7 +483,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
Expand All @@ -499,7 +499,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -523,7 +523,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0810"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
<key>orderHint</key>
<integer>0</integer>
</dict>
<key>SwiftLocationDemo.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
Expand All @@ -22,6 +27,11 @@
<key>primary</key>
<true/>
</dict>
<key>213F85071D61C7FC00835DCA</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
20 changes: 10 additions & 10 deletions SwiftLocation/SwiftLocationDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

var r = Location.getLocation(withAccuracy: .city, frequency: .continuous, timeout: nil, onSuccess: { (loc) in
print("loc \(loc)")
}) { (last, err) in
print("err \(err)")
}
r.onAuthorizationDidChange = { newStatus in
print("New status \(newStatus)")
}
// var r = Location.getLocation(withAccuracy: .city, frequency: .continuous, timeout: nil, onSuccess: { (loc) in
// print("loc \(loc)")
// }) { (last, err) in
// print("err \(err)")
// }
// r.onAuthorizationDidChange = { newStatus in
// print("New status \(newStatus)")
// }

// // Do any additional setup after loading the view, typically from a nib.
// let major = CLBeaconMajorValue(64224)
// let minor = CLBeaconMinorValue(43514)
// let proximity = "00194D5B-0A08-4697-B81C-C9BDE117412E"
//
//
// print("Beacon monitoring started \(proximity) - maj=\(major), min=\(minor)")
//
//
// do {
// let beacon = Beacon(proximity: proximity, major: major, minor: minor)
// try Beacons.monitor(beacon: beacon, events: Event.RegionBoundary, onStateDidChange: { state in
Expand Down
2 changes: 1 addition & 1 deletion SwiftLocation/SwiftLocationTests/SwiftLocationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SwiftLocationTests: XCTestCase {

func testPerformanceExample() {
// This is an example of a performance test case.
self.measureBlock {
self.measure {
// Put the code you want to measure the time of here.
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/BeaconAdvertiseRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ open class BeaconAdvertiseRequest: NSObject, Request {
}
}

internal func dataToAdvertise() -> [String:AnyObject?] {
let data: [String:AnyObject?] = [
CBAdvertisementDataLocalNameKey : self.name as ImplicitlyUnwrappedOptional<AnyObject>,
internal func dataToAdvertise() -> [String:Any] {
let data: [String:Any] = [
CBAdvertisementDataLocalNameKey : self.name as ImplicitlyUnwrappedOptional<Any>,
CBAdvertisementDataManufacturerDataKey : self.region.peripheralData(withMeasuredPower: self.RSSIPower),
CBAdvertisementDataServiceUUIDsKey : self.UUID as Optional<AnyObject>]
CBAdvertisementDataServiceUUIDsKey : self.UUID]
return data
}

Expand Down
4 changes: 2 additions & 2 deletions src/BeaconsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ open class BeaconsManager : NSObject, CLLocationManagerDelegate, CBPeripheralMan
}

internal func cancelAllMonitorsForRegion(_ error: LocationError) {
let list: [[AnyObject]] = [self.monitoredBeaconRegions,self.monitoredGeoRegions]
let list: [[Any]] = [self.monitoredBeaconRegions,self.monitoredGeoRegions]
list.forEach { queue in
queue.forEach({ request in
_ = self.remove(request: (request as! Request) , error: error)
Expand All @@ -261,7 +261,7 @@ open class BeaconsManager : NSObject, CLLocationManagerDelegate, CBPeripheralMan
}

internal func startPendingMonitors() {
let list: [[AnyObject]] = [self.monitoredBeaconRegions,self.monitoredGeoRegions]
let list: [[Any]] = [self.monitoredBeaconRegions,self.monitoredGeoRegions]
list.forEach { queue in
queue.forEach({ request in
(request as! Request).start()
Expand Down
25 changes: 20 additions & 5 deletions src/Commons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,22 +177,36 @@ extension CLGeocoder: Request {

// MARK: - Support for Request protocol in NSURLSessionDataTast object

extension URLSessionDataTask: Request {
public class NetRequest: Request {

private var task: URLSessionDataTask

public init(_ APIURLRequest: URLRequest, complete: @escaping ((Data?, Error?) -> Void)) {
let sessionConfig = URLSessionConfiguration.default
let session = URLSession(configuration: sessionConfig)
self.task = session.dataTask(with: APIURLRequest, completionHandler: { data, response, error in
complete(data,error)
})
}

public func cancel() {
task.cancel()
}

public func pause() {
self.suspend()
task.suspend()
}

public func start() {
self.resume()
task.resume()
}

public var UUID: String {
return "\(self.hash)"
return "\(task.hash)"
}

public func cancel(_ error: LocationError?) {
self.cancel()
task.cancel()
}

public var rState: RequestState {
Expand All @@ -204,6 +218,7 @@ extension URLSessionDataTask: Request {
get { return nil }
set { }
}

}

/**
Expand Down
34 changes: 14 additions & 20 deletions src/LocationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,8 @@ open class LocationManager: NSObject, CLLocationManagerDelegate {
}
let urlString = "\(urlPrefix)ip-api.com/json?fields=lat,lon,status,country,countryCode,zip\(keyParam)"
let URLRequest = Foundation.URLRequest(url: URL(string: urlString)!, cachePolicy: .reloadIgnoringLocalAndRemoteCacheData, timeoutInterval: timeout ?? DefaultTimeout)

let sessionConfig = URLSessionConfiguration.default
let session = URLSession(configuration: sessionConfig)
let task = session.dataTask(with: URLRequest) { (data, response, error) in

let task = NetRequest(URLRequest, complete: { data, error in
if let data = data as Data? {
do {
if let resultDict = try JSONSerialization.jsonObject(with: data, options: []) as? NSDictionary {
Expand All @@ -357,8 +355,8 @@ open class LocationManager: NSObject, CLLocationManagerDelegate {
onError(nil,LocationError.locationManager(error: error))
}
}
}
task.resume()
})
task.start()
return task
}

Expand Down Expand Up @@ -613,9 +611,7 @@ open class LocationManager: NSObject, CLLocationManagerDelegate {
}
let APIURL = URL(string: APIURLString)
let APIURLRequest = URLRequest(url: APIURL!)
let sessionConfig = URLSessionConfiguration.default
let session = URLSession(configuration: sessionConfig)
let task = session.dataTask(with: APIURLRequest) { (data, response, error) in
let task = NetRequest(APIURLRequest, complete: { data, error in
if error != nil {
fHandler(LocationError.locationManager(error: error as NSError?))
} else {
Expand All @@ -632,8 +628,8 @@ open class LocationManager: NSObject, CLLocationManagerDelegate {
}
}
}
}
task.resume()
})
task.start()
return task
}

Expand All @@ -660,9 +656,7 @@ open class LocationManager: NSObject, CLLocationManagerDelegate {
APIURLString = APIURLString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)!
let APIURL = URL(string: APIURLString)
let APIURLRequest = URLRequest(url: APIURL!)
let sessionConfig = URLSessionConfiguration.default
let session = URLSession(configuration: sessionConfig)
let task = session.dataTask(with: APIURLRequest) { (data, response, error) in
let task = NetRequest(APIURLRequest, complete: { data, error in
if error != nil {
fHandler(LocationError.locationManager(error: error as NSError?))
} else {
Expand All @@ -679,8 +673,8 @@ open class LocationManager: NSObject, CLLocationManagerDelegate {
}
}
}
}
task.resume()
})
task.start()
return task
}

Expand All @@ -692,7 +686,7 @@ open class LocationManager: NSObject, CLLocationManagerDelegate {
throw LocationError.noDataReturned
}

var addressDict = [String:AnyObject]()
var addressDict = [String:Any]()
addressDict[CLPlacemarkDictionaryKey.kCountry] = resultDict["country"] as! NSString
addressDict[CLPlacemarkDictionaryKey.kCountryCode] = resultDict["countryCode"] as! NSString
addressDict[CLPlacemarkDictionaryKey.kPostCodeExtension] = resultDict["zip"] as! NSString
Expand All @@ -709,7 +703,7 @@ open class LocationManager: NSObject, CLLocationManagerDelegate {
fileprivate func parseGoogleLocationData(_ resultDict: NSDictionary) -> CLPlacemark {
let locationDict = (resultDict.value(forKey: "results") as! NSArray).firstObject as! NSDictionary

var addressDict = [String:AnyObject]()
var addressDict = [String:Any]()

// Parse coordinates
let geometry = locationDict.object(forKey: "geometry") as! NSDictionary
Expand All @@ -724,9 +718,9 @@ open class LocationManager: NSObject, CLLocationManagerDelegate {
addressDict[CLPlacemarkDictionaryKey.kState] = JSONComponent("administrative_area_level_1", inArray: addressComponents, ofType: "short_name")
addressDict[CLPlacemarkDictionaryKey.kStreet] = formattedAddressArray.first! as NSString
addressDict[CLPlacemarkDictionaryKey.kThoroughfare] = JSONComponent("route", inArray: addressComponents, ofType: "long_name")
addressDict[CLPlacemarkDictionaryKey.kFormattedAddressLines] = formattedAddressArray as AnyObject
addressDict[CLPlacemarkDictionaryKey.kFormattedAddressLines] = formattedAddressArray as Any
addressDict[CLPlacemarkDictionaryKey.kSubThoroughfare] = JSONComponent("street_number", inArray: addressComponents, ofType: "long_name")
addressDict[CLPlacemarkDictionaryKey.kPostCodeExtension] = "" as AnyObject
addressDict[CLPlacemarkDictionaryKey.kPostCodeExtension] = "" as Any
addressDict[CLPlacemarkDictionaryKey.kCity] = JSONComponent("locality", inArray: addressComponents, ofType: "long_name")
addressDict[CLPlacemarkDictionaryKey.kZIP] = JSONComponent("postal_code", inArray: addressComponents, ofType: "long_name")
addressDict[CLPlacemarkDictionaryKey.kCountry] = JSONComponent("country", inArray: addressComponents, ofType: "long_name")
Expand Down

0 comments on commit 8df37c3

Please sign in to comment.