             "deviceName": UIDevice.current.name,
             "deviceSystemName": UIDevice.current.systemName,
             "deviceSystemVersion": UIDevice.current.systemVersion
-        ])
+            ])
 
         if (success) {
+            print(Date(), "success update")
             lastUpdateTime = Date.init()
         }
-
-        let viewController = window?.rootViewController as! ViewController
-        let interval : TimeInterval = Date().timeIntervalSince(lastUpdateTime)
-        let intervalSeconds = Int(interval)
-        viewController.mySetLabelText(text: String(intervalSeconds))
+    }
+    
+    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
+        updateLocation()
     }
 
     func applicationWillResignActive(_ application: UIApplication) {


        UIDevice.current.isBatteryMonitoringEnabled = true

        locationManager = CLLocationManager()
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters // kCLLocationAccuracyBest
        locationManager.requestAlwaysAuthorization()
        locationManager.startUpdatingLocation()

        return true
    }
    
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        let location = locations.last! as CLLocation

        let success = sendJson(urlString: cloudUrlString, data: [
            "deviceId": deviceUuid(),


    func applicationDidEnterBackground(_ application: UIApplication) {
        print("applicationDidEnterBackground")
        timer.invalidate()
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        print("applicationWillEnterForeground")
        timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(timerEvent), userInfo: nil, repeats: true)
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
