I'm writing a program similar to runkeeper via Swift that keeps track of a user's movement. I do not have any trouble in monitoring the user's location, however, I am wondering if there is a way to determine whether a user has entered a building or not.
Geofencing crossed my mind but that would mean determining every building a user enters.
Another thought that came to mind was continuously firing code that determines the user's signal (but this seems a bit annoying--although if this is the only choice I'm left with I'll do this). My reasoning behind this is if I cannot determine whether the user has entered a building or not, I can at least detect when they have a poor signal through the CoreTelephony framework.
Whenever a run is initialized (through an object I call WalkingEngine -- note it hasn't been implemented here yet), I use that WalkingEngine as part of my Reachability helper's custom init and begin the process of continuously sending that signal (there might be a better way to do this, such as wait for when the signal actually turns poor?) This is the code:
import Foundation
import CoreTelephony
//When can we detect whether we have a connection or not? You'll have to lose a connection.
//MARK: Initialize the actual enum? We don't know where it's going to implemented otherwise,
enum ConnectionQuality : Int {
case EBWConnectionQualityZero, EBWConnectionQualityLo, EBWConnectionQualityHi
}
class ReachabilityHelper {
//TODO Determine best initialization method. Check
//WalkEngine Init for reference
//MARK: Check Phone's general connection status
// func checkForGPSConnection () {
//
// let reachability: Reachability
// let networkStatus = reachability.currentReachabilityStatus
//
// switch (networkStatus) {
// case .NotReachable
//
// }
//
//
// }
//MARK: Check for the Phone's Connection Type
func radioAccessType() -> String {
//Print the current telephone's connection type for development
//purposes.
var radioTelephoneInfo: CTTelephonyNetworkInfo
print(radioTelephoneInfo)
radioTelephoneInfo.currentRadioAccessTechnology
}
//MARK: Check for the quality of the Connection Type
//TODO This is an incredibly ugly if-else statement. There are much more elegenat ways
//to express this via Swift. This code was written quickly so as to solve the problem.
func connectionQualityForTechnology(ebwConnectionQuality: ConnectionQuality) -> (radioAccessTechnology: String) {
if radioAccessTechnology == CTRadioAccessTechnologyGPRS {
return ConnectionQuality.EBWConnectionQualityZero
}
else if radioAccessTechnology == CTRadioAccessTechnologyEdge{
return ConnectionQuality.EBWConnectionQualityZero
}
else if radioAccessTechnology == CTRadioAccessTechnologyWCDMA {
return ConnectionQuality.EBWConnectionQualityLo
}
else if radioAccessTechnology == CTRadioAccessTechnologyHSDPA {
return ConnectionQuality.EBWConnectionQualityLo
}
else if radioAccessTechnology == CTRadioAccessTechnologyHSUPA {
return ConnectionQuality.EBWConnectionQualityLo
}
else if radioAccessTechnology == CTRadioAccessTechnologyCDMA1x {
return ConnectionQuality.EBWConnectionQualityZero
}
else if radioAccessTechnology == CTRadioAccessTechnologyCDMAEVDORev0 {
return ConnectionQuality.EBWConnectionQualityLo
}
else if radioAccessTechnology == CTRadioAccessTechnologyCDMAEVDORevA {
return ConnectionQuality.EBWConnectionQualityLo
}
else if radioAccessTechnology == CTRadioAccessTechnologyCDMAEVDORevB {
return ConnectionQuality.EBWConnectionQualityLo
}
else if radioAccessTechnology == CTRadioAccessTechnologyeHRPD {
return ConnectionQuality.EBWConnectionQualityHi
}
else if radioAccessTechnology == CTRadioAccessTechnologyLTE {
return ConnectionQuality.EBWConnectionQualityHi
}
return ConnectionQuality.EBWConnectionQualityHi
}
}