Skip to content

Commit

Permalink
Merge branch 'release/4.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
malcommac committed Nov 17, 2019
2 parents e1eb681 + 3b203f6 commit 0738a53
Show file tree
Hide file tree
Showing 17 changed files with 1,007 additions and 159 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -65,3 +65,4 @@ fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
.DS_Store
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions DemoApp/AppDelegate.swift
Expand Up @@ -16,18 +16,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.


let options = GeocoderRequest.GoogleOptions(APIKey: "AIzaSyBFNt-SA_YWs6avChK-sU5aMR3o7DRTH-8")
let google = GeocoderRequest.Service.google(options)
let x = LocationManager.shared.locateFromAddress("Via dei durantini 221, Rome", service: google) { data in
switch data {
case .failure(let error):
break
case .success(let value):
print(value)
}
}
return true
}

Expand Down
458 changes: 349 additions & 109 deletions DemoApp/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions DemoApp/Info.plist
Expand Up @@ -29,6 +29,8 @@
<string>We are requesting user auth to read GPS - ALWAYS</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>We are requesting user auth to read GPS - ONLY IN USE</string>
<key>UIUserInterfaceStyle</key>
<string>Light</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand Down
50 changes: 50 additions & 0 deletions DemoApp/Monitor Controller/BeaconsRequestCell.swift
@@ -0,0 +1,50 @@
//
// GPSRequestCell.swift
// DemoApp
//
// Created by dan on 23/04/2019.
// Copyright © 2019 SwiftLocation. All rights reserved.
//

import Foundation
import CoreLocation
import MapKit

public class BeaconsRequestCell: UITableViewCell {
public static let height: CGFloat = 70

@IBOutlet public var titleLabel: UILabel!
@IBOutlet public var descriptionLabel: UILabel!
@IBOutlet public var stopButton: UIButton!

internal weak var monitorController: RequestsMonitorController?

@IBAction public func didPressStop() {
if let request = request {
switch request.state {
case .expired:
monitorController?.completedRequests.removeAll(where: { $0.id == request.id })
monitorController?.reload()
default:
request.stop()
}
}
}

public var request: BeaconsRequest? {
didSet {
stopButton.setTitle( (request?.state == .running ? "Stop" : "Remove"), for: .normal)
titleLabel.text = "BEACONS MONITORING"

guard let beacons = request?.value else {
descriptionLabel.text = "(not received)"
return
}

let descritpion = beacons.compactMap { "\($0.major) \($0.minor)" }.joined(separator: " | ")
descriptionLabel.text = descritpion
stopButton.isEnabled = true
stopButton.alpha = 1.0
}
}
}
43 changes: 31 additions & 12 deletions DemoApp/Monitor Controller/RequestsMonitorController.swift
Expand Up @@ -19,11 +19,12 @@ class RequestsMonitorController: UIViewController {
@IBOutlet public var currentAuth: UILabel!
@IBOutlet public var currentAccuracy: UILabel!
@IBOutlet public var countLocationReqs: UILabel!
@IBOutlet public var countBeaconsReqs: UILabel!
@IBOutlet public var countLocationByIPReqs: UILabel!
@IBOutlet public var countGeocodingReqs: UILabel!
@IBOutlet public var countAutocompleteReqs: UILabel!
@IBOutlet public var countHeadingReqs: UILabel!

internal var completedRequests = [ServiceRequest]()

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

alert.addAction(UIAlertAction(title: "Monitor iBeacon", style: .default, handler: { _ in
self.present(NewBeaconsRequestController.create(), animated: true, completion: nil)
}))

alert.addAction(UIAlertAction(title: "Location by IP", style: .default, handler: { _ in
self.present(NewIPRequestController.create(), animated: true, completion: nil)
}))
Expand Down Expand Up @@ -102,26 +107,28 @@ class RequestsMonitorController: UIViewController {
extension RequestsMonitorController: UITableViewDataSource, UITableViewDelegate {

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

func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
let count = requestsForSection(section).count
if section != 5 && count == 0 {
if section != 6 && count == 0 {
return nil
}
switch section {
case 0:
return "\(count) GPS"
case 1:
return "\(count) IP LOCATION"
return "\(count) Beacons"
case 2:
return "\(count) GEOCODING"
return "\(count) IP LOCATION"
case 3:
return "\(count) HEADING"
return "\(count) GEOCODING"
case 4:
return "\(count) AUTOCOMPLETE"
return "\(count) HEADING"
case 5:
return "\(count) AUTOCOMPLETE"
case 6:
return "COMPLETED REQUESTS"
default:
return nil
Expand All @@ -133,14 +140,16 @@ extension RequestsMonitorController: UITableViewDataSource, UITableViewDelegate
case 0:
return Array(locator.queueLocationRequests)
case 1:
return Array(locator.queueLocationByIPRequests)
return Array(locator.queueBeaconsRequests)
case 2:
return Array(locator.queueGeocoderRequests)
return Array(locator.queueLocationByIPRequests)
case 3:
return Array(locator.queueHeadingRequests)
return Array(locator.queueGeocoderRequests)
case 4:
return Array(locator.queueAutocompleteRequests)
return Array(locator.queueHeadingRequests)
case 5:
return Array(locator.queueAutocompleteRequests)
case 6:
return completedRequests
default:
return []
Expand Down Expand Up @@ -168,6 +177,12 @@ extension RequestsMonitorController: UITableViewDataSource, UITableViewDelegate
cell.request = locRequest
cell.monitorController = self
return cell

case let beaconsRequest as BeaconsRequest:
let cell = tableView.dequeueReusableCell(withIdentifier: "BeaconsRequestCell") as! BeaconsRequestCell
cell.request = beaconsRequest
cell.monitorController = self
return cell

case let ipRequest as LocationByIPRequest:
let cell = tableView.dequeueReusableCell(withIdentifier: "IPRequestCell") as! IPRequestCell
Expand Down Expand Up @@ -197,7 +212,10 @@ extension RequestsMonitorController: UITableViewDataSource, UITableViewDelegate
switch request {
case _ as LocationRequest:
return GPSRequestCell.height


case _ as BeaconsRequest:
return BeaconsRequestCell.height

case _ as LocationByIPRequest:
return IPRequestCell.height

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

countHeadingReqs.text = String(locator.queueHeadingRequests.count)
countLocationReqs.text = String(locator.queueLocationRequests.count)
countBeaconsReqs.text = String(locator.queueBeaconsRequests.count)
countGeocodingReqs.text = String(locator.queueGeocoderRequests.count)
countAutocompleteReqs.text = String(locator.queueAutocompleteRequests.count)
countLocationByIPReqs.text = String(locator.queueLocationByIPRequests.count)
Expand Down
120 changes: 120 additions & 0 deletions DemoApp/New Requests/NewBeaconsRequestController.swift
@@ -0,0 +1,120 @@
//
// NewGPSRequestController.swift
// SwiftLocation
//
// Created by dan on 23/04/2019.
// Copyright © 2019 SwiftLocation. All rights reserved.
//

import UIKit
import CoreLocation

public class NewBeaconsRequestController: UIViewController {

@IBOutlet public var timeoutButton: UIButton!
@IBOutlet public var modeButton: UIButton!
@IBOutlet public var distanceFilter: UITextField!
@IBOutlet public var proximityUUID: UITextField!
@IBOutlet public var activityButton: UIButton!

private var timeout: Timeout.Mode? = nil {
didSet {
reload()
}
}

private var mode: BeaconsRequest.Subscription = .oneShot {
didSet {
reload()
}
}

private var activityType: CLActivityType = .other {
didSet {
reload()
}
}

public static func create() -> UINavigationController {
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
let vc = storyboard.instantiateViewController(withIdentifier: "NewBeaconsRequestController") as! NewBeaconsRequestController
return UINavigationController(rootViewController: vc)
}

public override func viewDidLoad() {
super.viewDidLoad()

self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(didPressCancel))
self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Create", style: .plain, target: self, action: #selector(createRequest))

self.timeout = .delayed(10)
self.mode = .oneShot
reload()
}

@objc func didPressCancel() {
self.dismiss(animated: true, completion: nil)
}


@IBAction public func setMode() {
let options: [SelectionItem<BeaconsRequest.Subscription>] = BeaconsRequest.Subscription.all.map {
return SelectionItem(title: $0.description, value: $0)
}
self.showPicker(title: "Select a Subscription mode", msg: nil, options: options, onSelect: { item in
self.mode = item.value!
})
}

@IBAction public func setActivityType() {
var options: [SelectionItem<CLActivityType>] = [
SelectionItem(title: "other", value: CLActivityType.other),
SelectionItem(title: "automotiveNavigation", value: CLActivityType.automotiveNavigation),
SelectionItem(title: "fitness", value: CLActivityType.fitness),
SelectionItem(title: "otherNavigation", value: CLActivityType.otherNavigation),
]

if #available(iOS 12.0, *) {
options.append(SelectionItem(title: "airborne", value: CLActivityType.airborne))
}

self.showPicker(title: "Select an Activity", msg: nil, options: options, onSelect: { item in
self.activityType = item.value!
})
}

@IBAction public func setTimeout() {
let options: [SelectionItem<Timeout.Mode>] = [
.init(title: "Absolute 5s", value: .absolute(5)),
.init(title: "Absolute 10s", value: .absolute(10)),
.init(title: "Absolute 20s", value: .absolute(20)),
.init(title: "Delayed 5s", value: .delayed(5)),
.init(title: "Delayed 10s", value: .delayed(10)),
.init(title: "Delayed 20s", value: .delayed(20)),
.init(title: "No Timeout", value: nil),
]
self.showPicker(title: "Select a Timeout", msg: nil, options: options, onSelect: { item in
self.timeout = item.value
})
}

private func reload() {
timeoutButton.setTitle(timeout?.description ?? "not set", for: .normal)
modeButton.setTitle(mode.description, for: .normal)
activityButton.setTitle(activityType.description, for: .normal)
}

@objc public func createRequest() {
guard let proximityUUID = UUID(uuidString: proximityUUID.text ?? "") else {
let alert = UIAlertController(title: "Invalid Proximity UUID", message: "Invalid identifier of the beacon.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
self.present(alert, animated: true, completion: nil)
return
}

LocationManager.shared.locateFromBeacons(self.mode,
proximityUUID: proximityUUID,
result: nil)
self.dismiss(animated: true, completion: nil)
}
}
5 changes: 3 additions & 2 deletions DemoApp/New Requests/NewGPSRequestController.swift
Expand Up @@ -126,8 +126,9 @@ public class NewGPSRequestController: UIViewController {
accuracy: self.accuracy,
distance: CLLocationDistance(distanceFilter.text ?? "-1"),
activity: self.activityType,
timeout: self.timeout,
result: nil)
timeout: self.timeout) { result in
print("\(result)")
}
self.dismiss(animated: true, completion: nil)
}
}
Expand Down
3 changes: 3 additions & 0 deletions Package.swift
Expand Up @@ -5,6 +5,9 @@ import PackageDescription

let package = Package(
name: "SwiftLocation",
platforms: [
.iOS("9.3")
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
Expand Down

0 comments on commit 0738a53

Please sign in to comment.