在我的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模拟器上工作正常,但是当我在真实设备上运行时,后台进程无效。