问题
I'm having a problem getting Background fetch to work. See my code below. I added fetch as background mode in info.plist. I simulate the fetch using Debug -> Simulate background fetch. Nothing is output in the console log. I couldn't find any good examples of this in swift. Does anyone know how to get this working?
func application(application: UIApplication!, performFetchWithCompletionHandler
completionHandler: ((UIBackgroundFetchResult) -> Void)!) {
println("Background fetch occured!");
completionHandler(UIBackgroundFetchResult.NewData)
}
回答1:
I've been fighting this all morning and I have an unfortunate solution:
According to the "Known Issues" section in the Xcode 6 release notes:
The Xcode menu command Simulator Background Fetch does not work.
Use the menu command in iOS Simulator instead. (20145602)
The kicker is that there is no option in the Simulator to trigger this.
I've tested this and it's still an issue in Xcode 6.3.1
回答2:
Make sure you set the minimum background fetch interval after the application did finish launching like so. I would also double check under your project's app target to click on capabilities and make sure Background modes is on with background fetch on just to make sure you did not mess up some how when allowing it through the Info.plist.
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
UIApplication.sharedApplication().setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum)
return true
}
来源:https://stackoverflow.com/questions/27281562/background-fetch-not-working