Background fetch not working

一笑奈何 提交于 2019-12-13 01:39:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!