             test(nil)
         } else {
             sendLocalNotif("\(selectedCity()):未激活，不刷新", badge: -1)
-            if let unwrappedID = self.bgTaskID {
-                self.bgTaskID = nil
-                UIApplication.sharedApplication().endBackgroundTask(unwrappedID)
-            }
+            properlyEndBgTaskIfThereIsOne()
+        }
+    }
+    
+    func properlyEndBgTaskIfThereIsOne() {
+        if self.bgTaskID != UIBackgroundTaskInvalid {
+            UIApplication.sharedApplication().endBackgroundTask(self.bgTaskID)
+            self.bgTaskID = UIBackgroundTaskInvalid
         }
     }
     

            }
            self.isLoadingData = false
            completionHandler?(.NoData)
            if let unwrappedID = self.bgTaskID {
                self.bgTaskID = nil
                UIApplication.sharedApplication().endBackgroundTask(unwrappedID)
            }
        }
    }
    

    private var time: String? = "Invalid"
    var wcSession: WCSession?
    private var session: NSURLSession?
    private var bgTaskID: UIBackgroundTaskIdentifier = UIBackgroundTaskInvalid
    
    func registerBackgroundVOIPCallback() {
        let ret = UIApplication.sharedApplication().setKeepAliveTimeout(600) { () -> Void in
            NSLog("voip called...")
            self.properlyEndBgTaskIfThereIsOne()
            self.bgTaskID = UIApplication.sharedApplication().beginBackgroundTaskWithExpirationHandler({ () -> Void in
                self.fetchNewData()
            })
