应用程序后台进程在ios模拟器中正常运行但是当我在真实设备应用程序中检查时背景未运行

时间:2017-07-05 08:38:59

标签: ios

在我的AppDelegate中,我有:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

      UIApplication.shared.setMinimumBackgroundFetchInterval(2)

     return true

}

func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {  
  completionHandler(UIBackgroundFetchResult.newData)
}

viewDidload我有

override func viewDidLoad() {
        super.viewDidLoad()

_ = Timer.scheduledTimer(timeInterval: 40, target: self, selector: #selector(ViewController.printBackground

 ), userInfo: nil, repeats: true)

}

现在在我的视图控制器中我有一个功能

func printBackground(){

   print ("Background is woring")

}

它在iOS模拟器上工作正常,但是当我在真实设备上运行时,后台进程无效。

0 个答案:

没有答案