| 
					
				 | 
			
			
				@@ -17,7 +17,8 @@ class ViewController: UIViewController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @IBOutlet weak var noOfSentGPSToServer: UILabel! 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @IBOutlet weak var pauseSwitch: UISwitch! 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @IBOutlet weak var clickButton: UIButton! 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @IBOutlet weak var trackingActivateSwitch: UISwitch! 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     var locationManager: CLLocationManager? 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     var noOfSentPos: Int = 0 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -39,6 +40,32 @@ class ViewController: UIViewController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         locationManager?.distanceFilter = 100.0 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         locationManager?.allowsBackgroundLocationUpdates = true 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         pauseSwitch.isEnabled = false 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    func setupTimer() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        _ = Timer.scheduledTimer(withTimeInterval: 5.0, repeats: true) { timer in 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+             
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            print("New Timer fired!") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+             
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            let managedContext = self.appDelegate.persistentContainer.viewContext 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            let entity = NSEntityDescription.entity(forEntityName: "GPS", in: managedContext)! 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            let fetchRequest = NSFetchRequest<NSManagedObject>(entityName: "GPS") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            do { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                self.gpsLogData = try managedContext.fetch(fetchRequest) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                print( "Cnt:" + String(self.gpsLogData.count) ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } catch let error as NSError { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                print("Could not fetch. \(error), \(error.userInfo)") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if( self.trackingActivateSwitch.isOn == false ) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                timer.invalidate() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                print("Stopping Timer") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @objc func fireTimer() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @IBAction func tackingPauseChanged(_ sender: UISwitch) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -58,8 +85,6 @@ class ViewController: UIViewController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         switch sender.isOn { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         case true: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             let managedContext = appDelegate.persistentContainer.viewContext 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            //let entity = NSEntityDescription.entity(forEntityName: "GPS", in: managedContext)! 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            //let fetchRequest = NSFetchRequest<NSManagedObject>(entityName: "GPS") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "GPS") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             let batchDeleteRequest = NSBatchDeleteRequest(fetchRequest: fetchRequest) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             do { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -71,6 +96,8 @@ class ViewController: UIViewController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             locationManager?.startUpdatingLocation() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             pauseSwitch.isEnabled = true 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             noOfSentPos = 0 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //activateBackgroundTask() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            setupTimer() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         default: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             print("OFF") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             locationManager?.stopUpdatingLocation() 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -79,17 +106,7 @@ class ViewController: UIViewController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    func viewDidBecomeActive(){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        print("viewDidBecomeActive") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    override func viewDidDisappear(_ animated: Bool) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        print("viewDidBecomeINActive") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 extension ViewController: CLLocationManagerDelegate { 
			 |