-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataCollectingViewController.swift
More file actions
66 lines (51 loc) · 1.81 KB
/
DataCollectingViewController.swift
File metadata and controls
66 lines (51 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// DataCollectingController.swift
// CRC_iOS
//
// Created by 우예지 on 2021/05/11.
//
import UIKit
let TIME = 660
class DataCollectingViewController: UIViewController {
let data = DataCollect()
// View
override func viewDidLoad() {
super.viewDidLoad()
UIApplication.shared.isIdleTimerDisabled = true // prevent screen from turning off while data collecting
startTimer()
}
override func viewDidAppear(_ animated: Bool) {
data.startGetSensorData() // start data collecting
data.startGetGPSData()
data.writeInFile()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func endView() {
data.endGetSensorData() // end data collecting
data.endGetGPSData()
// new view
let mainStoryBoard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let Survey2View = mainStoryBoard.instantiateViewController(identifier: "Survey2")
Survey2View.modalTransitionStyle = UIModalTransitionStyle.coverVertical
Survey2View.modalPresentationStyle = .overFullScreen
self.present(Survey2View, animated: true)
}
// Timer
@IBOutlet var timeLabel: UILabel!
var timer : Timer?
var timeLeft : Int = TIME
func startTimer() {
self.timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(DataCollectingViewController.timerCallBack), userInfo: nil, repeats: true)
RunLoop.current.add(self.timer!, forMode: RunLoop.Mode.default)
}
@objc func timerCallBack() {
timeLeft -= 1
timeLabel.text = String(timeLeft) + " seconds remaining..."
if timeLeft == 0 {
timer?.invalidate()
endView()
}
}
}