我在我的AppDelegate下面的代码:迅速后台取指不工作
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil))
application.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum)
return true
}
func application(application: UIApplication, performFetchWithCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
completionHandler(UIBackgroundFetchResult.NewData)
getData()
}
func getData(){
// function that gets certain data from the server and notifies the
// user of the info fetched
}
我这里面临两个问题:
的第一个问题是,后台提取所从来没有,除非执行我点击“调试>模拟背景获取”。我无限期地等待着它,它从来没有被自己调用过。
第二个问题是,当我点击模拟背景获取,而我的应用程序仍然打开时,模拟器存在应用程序,然后执行后台获取,即使应用程序运行时后台获取仍应该工作并没有关闭它。
我是否缺少任何与背景获取相关的代码?还是有任何错误的代码?这是我编写的唯一一个与后台提取相关的代码,而不是将背景提取添加到功能。
但如果用户的手机系统决定触发当用户正在使用的应用程序在后台读取,完成这个关闭,他/她的应用程序,而他们在使用它? biz我想到了“模拟后台获取”类似于系统的执行情况,这就是当我运行“模拟后台获取”时发生的事情。 –
如果用户使用的应用程序,它不是后台,所以永远不会被触发。 – Agreensh