Skip to content

Commit 0738a53

Browse files
committed
Merge branch 'release/4.2.0'
2 parents e1eb681 + 3b203f6 commit 0738a53

File tree

17 files changed

+1007
-159
lines changed

17 files changed

+1007
-159
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,4 @@ fastlane/report.xml
6565
fastlane/Preview.html
6666
fastlane/screenshots
6767
fastlane/test_output
68+
.DS_Store

.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DemoApp/AppDelegate.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1616

1717
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
1818
// Override point for customization after application launch.
19-
20-
21-
let options = GeocoderRequest.GoogleOptions(APIKey: "AIzaSyBFNt-SA_YWs6avChK-sU5aMR3o7DRTH-8")
22-
let google = GeocoderRequest.Service.google(options)
23-
let x = LocationManager.shared.locateFromAddress("Via dei durantini 221, Rome", service: google) { data in
24-
switch data {
25-
case .failure(let error):
26-
break
27-
case .success(let value):
28-
print(value)
29-
}
30-
}
3119
return true
3220
}
3321

DemoApp/Base.lproj/Main.storyboard

Lines changed: 349 additions & 109 deletions
Large diffs are not rendered by default.

DemoApp/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
<string>We are requesting user auth to read GPS - ALWAYS</string>
3030
<key>NSLocationWhenInUseUsageDescription</key>
3131
<string>We are requesting user auth to read GPS - ONLY IN USE</string>
32+
<key>UIUserInterfaceStyle</key>
33+
<string>Light</string>
3234
<key>UILaunchStoryboardName</key>
3335
<string>LaunchScreen</string>
3436
<key>UIMainStoryboardFile</key>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//
2+
// GPSRequestCell.swift
3+
// DemoApp
4+
//
5+
// Created by dan on 23/04/2019.
6+
// Copyright © 2019 SwiftLocation. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import CoreLocation
11+
import MapKit
12+
13+
public class BeaconsRequestCell: UITableViewCell {
14+
public static let height: CGFloat = 70
15+
16+
@IBOutlet public var titleLabel: UILabel!
17+
@IBOutlet public var descriptionLabel: UILabel!
18+
@IBOutlet public var stopButton: UIButton!
19+
20+
internal weak var monitorController: RequestsMonitorController?
21+
22+
@IBAction public func didPressStop() {
23+
if let request = request {
24+
switch request.state {
25+
case .expired:
26+
monitorController?.completedRequests.removeAll(where: { $0.id == request.id })
27+
monitorController?.reload()
28+
default:
29+
request.stop()
30+
}
31+
}
32+
}
33+
34+
public var request: BeaconsRequest? {
35+
didSet {
36+
stopButton.setTitle( (request?.state == .running ? "Stop" : "Remove"), for: .normal)
37+
titleLabel.text = "BEACONS MONITORING"
38+
39+
guard let beacons = request?.value else {
40+
descriptionLabel.text = "(not received)"
41+
return
42+
}
43+
44+
let descritpion = beacons.compactMap { "\($0.major) \($0.minor)" }.joined(separator: " | ")
45+
descriptionLabel.text = descritpion
46+
stopButton.isEnabled = true
47+
stopButton.alpha = 1.0
48+
}
49+
}
50+
}

DemoApp/Monitor Controller/RequestsMonitorController.swift

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ class RequestsMonitorController: UIViewController {
1919
@IBOutlet public var currentAuth: UILabel!
2020
@IBOutlet public var currentAccuracy: UILabel!
2121
@IBOutlet public var countLocationReqs: UILabel!
22+
@IBOutlet public var countBeaconsReqs: UILabel!
2223
@IBOutlet public var countLocationByIPReqs: UILabel!
2324
@IBOutlet public var countGeocodingReqs: UILabel!
2425
@IBOutlet public var countAutocompleteReqs: UILabel!
2526
@IBOutlet public var countHeadingReqs: UILabel!
26-
27+
2728
internal var completedRequests = [ServiceRequest]()
2829

2930
private var timer: Timer?
@@ -65,6 +66,10 @@ class RequestsMonitorController: UIViewController {
6566
self.present(NewGPSRequestController.create(), animated: true, completion: nil)
6667
}))
6768

69+
alert.addAction(UIAlertAction(title: "Monitor iBeacon", style: .default, handler: { _ in
70+
self.present(NewBeaconsRequestController.create(), animated: true, completion: nil)
71+
}))
72+
6873
alert.addAction(UIAlertAction(title: "Location by IP", style: .default, handler: { _ in
6974
self.present(NewIPRequestController.create(), animated: true, completion: nil)
7075
}))
@@ -102,26 +107,28 @@ class RequestsMonitorController: UIViewController {
102107
extension RequestsMonitorController: UITableViewDataSource, UITableViewDelegate {
103108

104109
func numberOfSections(in tableView: UITableView) -> Int {
105-
return 6 // all kinds + completed requests
110+
return 7 // all kinds + completed requests
106111
}
107112

108113
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
109114
let count = requestsForSection(section).count
110-
if section != 5 && count == 0 {
115+
if section != 6 && count == 0 {
111116
return nil
112117
}
113118
switch section {
114119
case 0:
115120
return "\(count) GPS"
116121
case 1:
117-
return "\(count) IP LOCATION"
122+
return "\(count) Beacons"
118123
case 2:
119-
return "\(count) GEOCODING"
124+
return "\(count) IP LOCATION"
120125
case 3:
121-
return "\(count) HEADING"
126+
return "\(count) GEOCODING"
122127
case 4:
123-
return "\(count) AUTOCOMPLETE"
128+
return "\(count) HEADING"
124129
case 5:
130+
return "\(count) AUTOCOMPLETE"
131+
case 6:
125132
return "COMPLETED REQUESTS"
126133
default:
127134
return nil
@@ -133,14 +140,16 @@ extension RequestsMonitorController: UITableViewDataSource, UITableViewDelegate
133140
case 0:
134141
return Array(locator.queueLocationRequests)
135142
case 1:
136-
return Array(locator.queueLocationByIPRequests)
143+
return Array(locator.queueBeaconsRequests)
137144
case 2:
138-
return Array(locator.queueGeocoderRequests)
145+
return Array(locator.queueLocationByIPRequests)
139146
case 3:
140-
return Array(locator.queueHeadingRequests)
147+
return Array(locator.queueGeocoderRequests)
141148
case 4:
142-
return Array(locator.queueAutocompleteRequests)
149+
return Array(locator.queueHeadingRequests)
143150
case 5:
151+
return Array(locator.queueAutocompleteRequests)
152+
case 6:
144153
return completedRequests
145154
default:
146155
return []
@@ -168,6 +177,12 @@ extension RequestsMonitorController: UITableViewDataSource, UITableViewDelegate
168177
cell.request = locRequest
169178
cell.monitorController = self
170179
return cell
180+
181+
case let beaconsRequest as BeaconsRequest:
182+
let cell = tableView.dequeueReusableCell(withIdentifier: "BeaconsRequestCell") as! BeaconsRequestCell
183+
cell.request = beaconsRequest
184+
cell.monitorController = self
185+
return cell
171186

172187
case let ipRequest as LocationByIPRequest:
173188
let cell = tableView.dequeueReusableCell(withIdentifier: "IPRequestCell") as! IPRequestCell
@@ -197,7 +212,10 @@ extension RequestsMonitorController: UITableViewDataSource, UITableViewDelegate
197212
switch request {
198213
case _ as LocationRequest:
199214
return GPSRequestCell.height
200-
215+
216+
case _ as BeaconsRequest:
217+
return BeaconsRequestCell.height
218+
201219
case _ as LocationByIPRequest:
202220
return IPRequestCell.height
203221

@@ -217,6 +235,7 @@ extension RequestsMonitorController: UITableViewDataSource, UITableViewDelegate
217235

218236
countHeadingReqs.text = String(locator.queueHeadingRequests.count)
219237
countLocationReqs.text = String(locator.queueLocationRequests.count)
238+
countBeaconsReqs.text = String(locator.queueBeaconsRequests.count)
220239
countGeocodingReqs.text = String(locator.queueGeocoderRequests.count)
221240
countAutocompleteReqs.text = String(locator.queueAutocompleteRequests.count)
222241
countLocationByIPReqs.text = String(locator.queueLocationByIPRequests.count)
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
//
2+
// NewGPSRequestController.swift
3+
// SwiftLocation
4+
//
5+
// Created by dan on 23/04/2019.
6+
// Copyright © 2019 SwiftLocation. All rights reserved.
7+
//
8+
9+
import UIKit
10+
import CoreLocation
11+
12+
public class NewBeaconsRequestController: UIViewController {
13+
14+
@IBOutlet public var timeoutButton: UIButton!
15+
@IBOutlet public var modeButton: UIButton!
16+
@IBOutlet public var distanceFilter: UITextField!
17+
@IBOutlet public var proximityUUID: UITextField!
18+
@IBOutlet public var activityButton: UIButton!
19+
20+
private var timeout: Timeout.Mode? = nil {
21+
didSet {
22+
reload()
23+
}
24+
}
25+
26+
private var mode: BeaconsRequest.Subscription = .oneShot {
27+
didSet {
28+
reload()
29+
}
30+
}
31+
32+
private var activityType: CLActivityType = .other {
33+
didSet {
34+
reload()
35+
}
36+
}
37+
38+
public static func create() -> UINavigationController {
39+
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
40+
let vc = storyboard.instantiateViewController(withIdentifier: "NewBeaconsRequestController") as! NewBeaconsRequestController
41+
return UINavigationController(rootViewController: vc)
42+
}
43+
44+
public override func viewDidLoad() {
45+
super.viewDidLoad()
46+
47+
self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(didPressCancel))
48+
self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Create", style: .plain, target: self, action: #selector(createRequest))
49+
50+
self.timeout = .delayed(10)
51+
self.mode = .oneShot
52+
reload()
53+
}
54+
55+
@objc func didPressCancel() {
56+
self.dismiss(animated: true, completion: nil)
57+
}
58+
59+
60+
@IBAction public func setMode() {
61+
let options: [SelectionItem<BeaconsRequest.Subscription>] = BeaconsRequest.Subscription.all.map {
62+
return SelectionItem(title: $0.description, value: $0)
63+
}
64+
self.showPicker(title: "Select a Subscription mode", msg: nil, options: options, onSelect: { item in
65+
self.mode = item.value!
66+
})
67+
}
68+
69+
@IBAction public func setActivityType() {
70+
var options: [SelectionItem<CLActivityType>] = [
71+
SelectionItem(title: "other", value: CLActivityType.other),
72+
SelectionItem(title: "automotiveNavigation", value: CLActivityType.automotiveNavigation),
73+
SelectionItem(title: "fitness", value: CLActivityType.fitness),
74+
SelectionItem(title: "otherNavigation", value: CLActivityType.otherNavigation),
75+
]
76+
77+
if #available(iOS 12.0, *) {
78+
options.append(SelectionItem(title: "airborne", value: CLActivityType.airborne))
79+
}
80+
81+
self.showPicker(title: "Select an Activity", msg: nil, options: options, onSelect: { item in
82+
self.activityType = item.value!
83+
})
84+
}
85+
86+
@IBAction public func setTimeout() {
87+
let options: [SelectionItem<Timeout.Mode>] = [
88+
.init(title: "Absolute 5s", value: .absolute(5)),
89+
.init(title: "Absolute 10s", value: .absolute(10)),
90+
.init(title: "Absolute 20s", value: .absolute(20)),
91+
.init(title: "Delayed 5s", value: .delayed(5)),
92+
.init(title: "Delayed 10s", value: .delayed(10)),
93+
.init(title: "Delayed 20s", value: .delayed(20)),
94+
.init(title: "No Timeout", value: nil),
95+
]
96+
self.showPicker(title: "Select a Timeout", msg: nil, options: options, onSelect: { item in
97+
self.timeout = item.value
98+
})
99+
}
100+
101+
private func reload() {
102+
timeoutButton.setTitle(timeout?.description ?? "not set", for: .normal)
103+
modeButton.setTitle(mode.description, for: .normal)
104+
activityButton.setTitle(activityType.description, for: .normal)
105+
}
106+
107+
@objc public func createRequest() {
108+
guard let proximityUUID = UUID(uuidString: proximityUUID.text ?? "") else {
109+
let alert = UIAlertController(title: "Invalid Proximity UUID", message: "Invalid identifier of the beacon.", preferredStyle: .alert)
110+
alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
111+
self.present(alert, animated: true, completion: nil)
112+
return
113+
}
114+
115+
LocationManager.shared.locateFromBeacons(self.mode,
116+
proximityUUID: proximityUUID,
117+
result: nil)
118+
self.dismiss(animated: true, completion: nil)
119+
}
120+
}

DemoApp/New Requests/NewGPSRequestController.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ public class NewGPSRequestController: UIViewController {
126126
accuracy: self.accuracy,
127127
distance: CLLocationDistance(distanceFilter.text ?? "-1"),
128128
activity: self.activityType,
129-
timeout: self.timeout,
130-
result: nil)
129+
timeout: self.timeout) { result in
130+
print("\(result)")
131+
}
131132
self.dismiss(animated: true, completion: nil)
132133
}
133134
}

Package.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import PackageDescription
55

66
let package = Package(
77
name: "SwiftLocation",
8+
platforms: [
9+
.iOS("9.3")
10+
],
811
products: [
912
// Products define the executables and libraries produced by a package, and make them visible to other packages.
1013
.library(

0 commit comments

Comments
 (0)