Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Background Fetch Not Working Even Though Correct Background Mode Configured

My app has background modes enabled with Background Fetch checked and I validated the plist includes the appropriate fetch mode.

I have also configured the interval as follows:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {     application.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum);     return true; } 

And I have added the handler as follows:

func application(application: UIApplication, performFetchWithCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {     // Get some new data here     completionHandler(UIBackgroundFetchResult.NewData); } 

I tried going to Debug->Simulate Background Fetch, but no matter what it never enters the performFetchWithCompletionHandler. I also tried to run the app under a scheme that has the "Launch due to a background fetch event" option checked. Running under this scheme simply launches the application as usual in the simulator with no call to performFetchWithCompletionHandler.

Any ideas?

Thank you!

EDIT: This appears to be affecting the release version of my app as well so it may not be isolated to the simulator. I am running Swift 1.2.

EDIT 2: My bug report was just closed because it is a duplicate of another bug report outlining the same issue. There is still no information confirming the issue is isolated to the simulator.

EDIT 3: No mention of a fix in the Xcode 6.4 Beta 2 release notes. :-(

like image 220
a432511 Avatar asked Apr 13 '15 01:04

a432511


People also ask

Does background fetch work when app is terminated?

The Background Fetching will NOT happen in your app after the user has killed it in the multitasking UI. This is by design.

What is background fetch in iOS?

Background fetch is a new mode that lets your app appear always up-to-date with the latest information while minimizing the impact on battery. You could download feeds within fixed time intervals with this capability. To get started: 1- Check Background Fetch in capabilities screen in Xcode.

How do I enable background mode in Xcode?

Select your app's target in Xcode and select the Capabilities tab. Under the Capabilities tab, set the Background Modes switch to ON and select the “Audio, AirPlay, and Picture in Picture” option under the list of available modes.


2 Answers

Here's the only way I've found to test background fetch.

  1. Edit your scheme
  2. Select Run
  3. Select Options
  4. Check the "Launch due to background fetch event" option
  5. Plug-In your iOS Device and run the application on it. It does not work in the iOS Simulator.

Visual of Step 2-4

like image 83
Tobias Avatar answered Oct 02 '22 15:10

Tobias


Take a look on the XCode release note: https://developer.apple.com/library/ios/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html

"The Xcode menu command Simulator Background Fetch does not work.

Use the menu command in iOS Simulator instead. (20145602)"

like image 25
odemolliens Avatar answered Oct 02 '22 13:10

odemolliens