 
     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) {

    var locationManager: CLLocationManager!
    var cloudUrlString = "https://steptracker.tw1.ru/track.php"
    var lastUpdateTime : Date!
    
    func deviceUuid() -> String {
        return (UIDevice.current.identifierForVendor?.uuidString)!
    }
    
    func sendJson(urlString: String, data: Any) -> Bool {
        var jsonData : Data
        do {

            "deviceName": UIDevice.current.name,
            "deviceSystemName": UIDevice.current.systemName,
            "deviceSystemVersion": UIDevice.current.systemVersion
            ])

        if (success) {
            print(Date(), "success update")
            lastUpdateTime = Date.init()
        }
    }
    
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        updateLocation()
    }

    func applicationWillResignActive(_ application: UIApplication) {
