mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-02 18:33:54 +00:00
- added start / stop tracking button and logic to view controller
- made core location object private - added is tracking property
This commit is contained in:
1 parent
72cceebb1b
commit
bcfae0c70a
3 files changed
+49
-11
No files matched your search
@@ -1,8 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6245" systemVersion="13F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6250" systemVersion="14A389" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
|
||||
<dependencies>
|
||||
<deployment defaultVersion="1792" identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6238"/>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6244"/>
|
||||
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--View Controller-->
|
||||
@@ -16,8 +17,27 @@
|
||||
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<subviews>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="wn7-xc-GeE">
|
||||
<rect key="frame" x="16" y="550" width="568" height="30"/>
|
||||
<state key="normal" title="Start Tracking">
|
||||
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
|
||||
</state>
|
||||
<connections>
|
||||
<action selector="trackingButtonTap:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="YWK-JE-HP8"/>
|
||||
</connections>
|
||||
</button>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="bottom" secondItem="wn7-xc-GeE" secondAttribute="bottom" constant="20" symbolic="YES" id="Hcs-7I-pp6"/>
|
||||
<constraint firstItem="wn7-xc-GeE" firstAttribute="trailing" secondItem="kh9-bI-dsS" secondAttribute="trailingMargin" id="QF2-xS-Nz5"/>
|
||||
<constraint firstItem="wn7-xc-GeE" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leadingMargin" id="WcO-n7-hfK"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<connections>
|
||||
<outlet property="trackingButton" destination="wn7-xc-GeE" id="Yui-KO-5Jr"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
|
||||
@@ -26,11 +26,13 @@ class LocationManager: NSObject, CLLocationManagerDelegate {
|
||||
return Singleton.sharedLocationManager
|
||||
}
|
||||
|
||||
var locationManager: CLLocationManager = CLLocationManager();
|
||||
private var coreLocationManager: CLLocationManager = CLLocationManager()
|
||||
|
||||
var isTracking: Bool = false
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
locationManager.delegate = self
|
||||
coreLocationManager.delegate = self
|
||||
}
|
||||
|
||||
func startTracking() {
|
||||
@@ -40,16 +42,18 @@ class LocationManager: NSObject, CLLocationManagerDelegate {
|
||||
NSNotificationQueue.defaultQueue().enqueueNotification(notification, postingStyle: NSPostingStyle.PostASAP)
|
||||
return
|
||||
}
|
||||
locationManager.startUpdatingLocation()
|
||||
locationManager.startUpdatingHeading()
|
||||
locationManager.delegate = self
|
||||
coreLocationManager.startUpdatingLocation()
|
||||
coreLocationManager.startUpdatingHeading()
|
||||
coreLocationManager.delegate = self
|
||||
isTracking = true;
|
||||
let notification = NSNotification(name: NotificationType.trackingStartedNotificationKey, object: self)
|
||||
NSNotificationQueue.defaultQueue().enqueueNotification(notification, postingStyle: NSPostingStyle.PostASAP)
|
||||
}
|
||||
|
||||
func stopTracking() {
|
||||
locationManager.stopUpdatingLocation()
|
||||
locationManager.stopUpdatingHeading()
|
||||
coreLocationManager.stopUpdatingLocation()
|
||||
coreLocationManager.stopUpdatingHeading()
|
||||
isTracking = false;
|
||||
let notification = NSNotification(name: NotificationType.trackingStoppedNotificationKey, object: self)
|
||||
NSNotificationQueue.defaultQueue().enqueueNotification(notification, postingStyle: NSPostingStyle.PostASAP)
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import UIKit
|
||||
class ViewController: UIViewController {
|
||||
|
||||
|
||||
@IBOutlet weak var trackingButton: UIButton!
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
@@ -19,7 +21,6 @@ class ViewController: UIViewController {
|
||||
//DataManager.sharedManager
|
||||
// TODO: start only when button pressed
|
||||
DataManager.sharedManager
|
||||
LocationManager.sharedManager.startTracking()
|
||||
}
|
||||
|
||||
deinit {
|
||||
@@ -36,7 +37,20 @@ class ViewController: UIViewController {
|
||||
|
||||
func trackingStarted(notification: NSNotification) {
|
||||
println("trackingStarted")
|
||||
trackingButton.setTitle("Stop Tracking", forState: UIControlState.Normal)
|
||||
}
|
||||
|
||||
func trackingStopped(notification: NSNotification) {
|
||||
println("trackingStarted")
|
||||
trackingButton.setTitle("Start Tracking", forState: UIControlState.Normal)
|
||||
}
|
||||
|
||||
@IBAction func trackingButtonTap(sender: AnyObject) {
|
||||
if (LocationManager.sharedManager.isTracking) {
|
||||
LocationManager.sharedManager.stopTracking()
|
||||
} else {
|
||||
LocationManager.sharedManager.startTracking()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user