Skip to content

Commit

Permalink
Merge pull request #2 from cotrim149/dev
Browse files Browse the repository at this point in the history
Merging pull request from cotrim149 on dev branch
  • Loading branch information
fatalhck authored Nov 3, 2016
2 parents 4f0dd78 + 832eb45 commit 126e4ac
Show file tree
Hide file tree
Showing 12 changed files with 437 additions and 266 deletions.
6 changes: 3 additions & 3 deletions Findr.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'Findr'
s.version = '0.1.0'
s.version = '0.2.0'
s.summary = 'GeoLocation + iBeacons + Augmented Reality'

# This description is used to generate tags and improve search results.
Expand All @@ -28,10 +28,10 @@ TODO: Add long description of the pod here.
s.source = { :git => 'https://github.com/<GITHUB_USERNAME>/Findr.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

s.ios.deployment_target = '8.0'
s.ios.deployment_target = '9.0'

s.source_files = 'Findr/Classes/**/*'

# s.resource_bundles = {
# 'Findr' => ['Findr/Assets/*.png']
# }
Expand Down
16 changes: 8 additions & 8 deletions Findr/Classes/AdvertisingBeacon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public protocol BeaconAdvertisingDelegate {
func advertisingOperationDidFailToStart()
}

public class AdvertisingBeacon: NSObject, CBPeripheralManagerDelegate {
open class AdvertisingBeacon: NSObject, CBPeripheralManagerDelegate {

/// An instance of a CBPeripheralManager, which is used for advertising a beacon to nearby devices.
var peripheralManager = CBPeripheralManager(delegate: nil, queue: nil, options: nil)
Expand All @@ -39,8 +39,8 @@ public class AdvertisingBeacon: NSObject, CBPeripheralManagerDelegate {
self.peripheralManager.delegate = self
}

func broadcast(beacon: Beacon!) {
let beaconPeripheralData: NSDictionary = beacon.getRegion().peripheralDataWithMeasuredPower(nil) as NSDictionary
func broadcast(_ beacon: Beacon!) {
let beaconPeripheralData: NSDictionary = beacon.getRegion().peripheralData(withMeasuredPower: nil) as NSDictionary
self.peripheralManager.startAdvertising(beaconPeripheralData as? [String : AnyObject])
}

Expand All @@ -53,7 +53,7 @@ public class AdvertisingBeacon: NSObject, CBPeripheralManagerDelegate {

/// CBPeripheralManagerDelegate Delegates

public func peripheralManagerDidStartAdvertising(peripheral: CBPeripheralManager, error: NSError?) {
open func peripheralManagerDidStartAdvertising(_ peripheral: CBPeripheralManager, error: Error?) {
if error != nil {
print("Couldn't turn on advertising: \(error)")
delegate?.advertisingOperationDidFailToStart()
Expand All @@ -65,13 +65,13 @@ public class AdvertisingBeacon: NSObject, CBPeripheralManagerDelegate {
}
}

public func peripheralManagerDidUpdateState(peripheral: CBPeripheralManager) {
if peripheralManager.state == .PoweredOff {
open func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) {
if peripheralManager.state == .poweredOff {
print("Peripheral manager is off.")
delegate?.advertisingOperationDidFailToStart()
} else if peripheralManager.state == .PoweredOn {
} else if peripheralManager.state == .poweredOn {
print("Peripheral manager is on.")
}
}

}
}
18 changes: 9 additions & 9 deletions Findr/Classes/Beacon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
import Foundation
import CoreLocation

public class Beacon: NSObject {
open class Beacon: NSObject {
let identifier: String
let uuid: NSUUID
let uuid: UUID
let majorValue: CLBeaconMajorValue
let minorValue: CLBeaconMinorValue

public init(identifier: String, uuid: NSUUID, majorValue: CLBeaconMajorValue, minorValue: CLBeaconMinorValue) {
public init(identifier: String, uuid: UUID, majorValue: CLBeaconMajorValue, minorValue: CLBeaconMinorValue) {
self.identifier = identifier
self.uuid = uuid
self.majorValue = majorValue
self.minorValue = minorValue
}

public func getRegion() -> CLBeaconRegion {
open func getRegion() -> CLBeaconRegion {
let region = CLBeaconRegion(proximityUUID: self.uuid, major: self.majorValue, minor: self.minorValue, identifier: self.identifier)
return region
}
Expand All @@ -40,16 +40,16 @@ public extension CLBeacon
let proximityText: String

switch proximity {
case .Near:
case .near:
proximityText = "Near"
case .Immediate:
case .immediate:
proximityText = "Immediate"
case .Far:
case .far:
proximityText = "Far"
case .Unknown:
case .unknown:
proximityText = "Unknown"
}

return "\(major), \(minor)\(proximityText)\(accuracy)\(rssi)"
}
}
}
18 changes: 9 additions & 9 deletions Findr/Classes/BeaconController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ public protocol BeaconDelegate {

}

public class BeaconController: NSObject, CLLocationManagerDelegate {
open class BeaconController: NSObject, CLLocationManagerDelegate {
static let sharedInstance = BeaconController()

let locationManager = CLLocationManager()

let advertisingBeacon = AdvertisingBeacon()
let rangingBeacon = RangingBeacon()

private override init() {
fileprivate override init() {
super.init()
self.locationManager.delegate = self
}
Expand All @@ -30,26 +30,26 @@ public class BeaconController: NSObject, CLLocationManagerDelegate {
self.locationManager.requestAlwaysAuthorization()
}

func startRanging(beaconRegion: CLBeaconRegion!){
func startRanging(_ beaconRegion: CLBeaconRegion!){
beaconRegion.notifyEntryStateOnDisplay = true
self.rangingBeacon.startRanging(inRegion: beaconRegion, usingLocationManager: self.locationManager)
}

func stopRanging(beaconRegion: CLBeaconRegion!) {
func stopRanging(_ beaconRegion: CLBeaconRegion!) {
self.rangingBeacon.stopRanging(inRegion: beaconRegion, locationManager: self.locationManager)
}

// CLLocationManagerDelegate Delegates

public func locationManager(manager: CLLocationManager, monitoringDidFailForRegion region: CLRegion?, withError error: NSError) {
print("Failed monitoring region: \(error.description)")
open func locationManager(_ manager: CLLocationManager, monitoringDidFailFor region: CLRegion?, withError error: Error) {
print("Failed monitoring region: \(error.localizedDescription)")
}

public func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
print("Location manager failed: \(error.description)")
open func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print("Location manager failed: \(error.localizedDescription)")
}

public func locationManager(manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], inRegion region: CLBeaconRegion) {
open func locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion) {
//print("Region Major: \(region.major!) + Region Minor: \(region.minor!) + Region: \(region.proximityUUID.UUIDString)")

for beacon in beacons {
Expand Down
20 changes: 10 additions & 10 deletions Findr/Classes/FindrAnnotation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ import UIKit
import CoreLocation

/// Defines POI with title and location.
public class FindrAnnotation: NSObject
open class FindrAnnotation: NSObject
{
/// Title of annotation
public var title: String?
open var title: String?
/// Location of annotation
public var location: CLLocation?
open var location: CLLocation?

public var beaconDistance: Double?
open var beaconDistance: Double?

/// View for annotation. It is set inside ARViewController after fetching view from dataSource.
internal(set) public var annotationView: FindrAnnotationView?
internal(set) open var annotationView: FindrAnnotationView?

// Internal use only, do not set this properties
internal(set) public var distanceFromUser: Double = 0
internal(set) public var azimuth: Double = 0
internal(set) public var verticalLevel: Int = 0
internal(set) public var active: Bool = false
internal(set) open var distanceFromUser: Double = 0
internal(set) open var azimuth: Double = 0
internal(set) open var verticalLevel: Int = 0
internal(set) open var active: Bool = false

public override var description: String{
open override var description: String{
get{
return "\(title) - \(location) - DFU: \(distanceFromUser) - VL: \(verticalLevel)"
}
Expand Down
16 changes: 8 additions & 8 deletions Findr/Classes/FindrAnnotationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import UIKit
/// View for annotation. Subclass to customize. Annotation views should be lightweight,
/// try to avoid xibs and autolayout.
/// bindUi method is called when distance/azimuth is set in ARViewController.
public class FindrAnnotationView: UIView
open class FindrAnnotationView: UIView
{
public weak var annotation: FindrAnnotation?{
open weak var annotation: FindrAnnotation?{
didSet{
bindUi()
}
}
private var initialized: Bool = false
fileprivate var initialized: Bool = false

public init()
{
super.init(frame: CGRectZero)
super.init(frame: CGRect.zero)
self.initializeInternal()
}

Expand All @@ -38,7 +38,7 @@ public class FindrAnnotationView: UIView
self.initializeInternal()
}

private func initializeInternal()
fileprivate func initializeInternal()
{
if self.initialized
{
Expand All @@ -48,19 +48,19 @@ public class FindrAnnotationView: UIView
self.initialize()
}

public override func awakeFromNib()
open override func awakeFromNib()
{
self.bindUi()
}

/// Will always be called once, no need to call super
public func initialize()
open func initialize()
{

}

/// Called when distance/azimuth changes, intended to be used in subclasses
public func bindUi()
open func bindUi()
{

}
Expand Down
32 changes: 25 additions & 7 deletions Findr/Classes/FindrConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ let H_PIXELS_PER_DEGREE: CGFloat = 14 // How many pix
let OVERLAY_VIEW_WIDTH: CGFloat = 360 * H_PIXELS_PER_DEGREE // 360 degrees x sensitivity

let MAX_VISIBLE_ANNOTATIONS: Int = 500 // Do not change, can affect performance
let MAX_VERTICAL_LEVELS: Int = 10 // Do not change, can affect performance
let MAX_VERTICAL_LEVELS: Int = 5 // Do not change, can affect performance

internal func radiansToDegrees(radians: Double) -> Double
internal func radiansToDegrees(_ radians: Double) -> Double
{
return (radians) * (180.0 / M_PI)
}

internal func degreesToRadians(degrees: Double) -> Double
internal func degreesToRadians(_ degrees: Double) -> Double
{
return (degrees) * (M_PI / 180.0)
}

/// Normalizes degree to 360
internal func normalizeDegree(degree: Double) -> Double
internal func normalizeDegree(_ degree: Double) -> Double
{
var degreeNormalized = fmod(degree, 360)
if degreeNormalized < 0
Expand All @@ -31,7 +31,7 @@ internal func normalizeDegree(degree: Double) -> Double
}

/// Finds shortes angle distance between two angles. Angles must be normalized(0-360)
internal func deltaAngle(angle1: Double, angle2: Double) -> Double
internal func deltaAngle(_ angle1: Double, angle2: Double) -> Double
{
var deltaAngle = angle1 - angle2

Expand All @@ -50,7 +50,7 @@ internal func deltaAngle(angle1: Double, angle2: Double) -> Double
@objc public protocol ARDataSource : NSObjectProtocol
{
/// Asks the data source to provide annotation view for annotation. Annotation view must be subclass of ARAnnotationView.
func ar(findrViewController: FindrViewController, viewForAnnotation: FindrAnnotation) -> FindrAnnotationView
func ar(_ findrViewController: FindrViewController, viewForAnnotation: FindrAnnotation) -> FindrAnnotationView

/**
* READ BEFORE IMPLEMENTING
Expand All @@ -64,8 +64,26 @@ internal func deltaAngle(angle1: Double, angle2: Double) -> Double
* - parameter location: Current location of the user
* - returns: Annotations to load, previous annotations are removed
*/
optional func ar(findrViewController: FindrViewController, shouldReloadWithLocation location: CLLocation) -> [FindrAnnotation]
@objc optional func ar(_ findrViewController: FindrViewController, shouldReloadWithLocation location: CLLocation) -> [FindrAnnotation]

}

//MARK: FindrViewController Delegate
protocol FindrViewControllerDelegate {

func findrViewControllerFixedVerticalPositionForAnnotation(findrViewController: FindrViewController)-> CGFloat?
func findrViewControllerWillShowAnnotationView(findrViewController: FindrViewController, annotationView: FindrAnnotationView)
func findrViewControllerWillReloadAnnotations(findrViewController: FindrViewController, annotations: [FindrAnnotation])
func findrViewControllerUserDidGetLost(findrViewController: FindrViewController) -> Void
func findrViewControllerViewForLeftIndicator(findrViewController: FindrViewController)-> UIView
func findrViewControllerViewForRightIndicator(findrViewController: FindrViewController) -> UIView
func findrViewControllerFrameForRightIndicator(findrViewController: FindrViewController) -> CGRect
func findrViewControllerFrameForLeftIndicator(findrViewController: FindrViewController) -> CGRect
func findrViewControllerUpdateLeftIndicatorView(findrViewController: FindrViewController, view: UIView)
func findrViewControllerUpdateRightIndicatorView(findrViewController: FindrViewController, view: UIView)
}





Loading

0 comments on commit 126e4ac

Please sign in to comment.