iOS app进入后台后 应用保活 后台保活

824 阅读1分钟

iOS app进入后台后 应用保活 后台保活

  var bgTaskID: UIBackgroundTaskIdentifier = 0

  func applicationWillResignActive(_ application: UIApplication) {



        bgTaskID = UIApplication.shared.beginBackgroundTask() {

            // Completion handler to be performed if time runs out

           print("bgTaskID = UIApplication.shared.beginBackgroundTask()")

        }


   }



func applicationDidBecomeActive(_ application: UIApplication) {

        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

        UIApplication.shared.endBackgroundTask(bgTaskID)

   }