Simulate Background Fetch not working in Xcode 8 beta

I've submitted a bug report for this issue but I'm hoping someone here may have seen or solved this already.


I'm just getting started with background fetching for my iOS app and I've been following the excellent tutorial available from Ray Wenderlich.

https://www.raywenderlich.com/92428/background-modes-ios-swift-tutorial


The tutorial code sample offered there works fine, after minor modification, in Xcode 7.3.1. But Xcode 8 beta breaks it. I let it auto-convert to Swift 3. The app builds and runs on my attached iPhone 6, but the app crashes when I select "Simulate Background Fetch" form the debug menu in Xcode.


I'm not getting enough information in the debugger to sort out the problem. (Noob here, can't read most of it.)


There is a view controller in the tutorial named "FetchViewController" containing functions updateUI() and fetch(). Here's a simpified version of the tutorial code that gets added to the AppDelegate class:


  func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void)
  {
    print("Well waddya know, the Fetch was called")
    FetchViewController().fetch {
            FetchViewController().updateUI()
            completionHandler(.newData)
          }
      }


As I said, this works fine and prints the text to the output console when the "Simulate Background Fetch" is selected. The app is sent to the background and the text gets printed almost immediately. And the called functions execute properly, as far as I can tell.


In Xcode 8 beta, the app goes to the background but then crashes. The text never prints.


Maybe a clue? I've added print lines to the AppDelegate to show when the app is changing state. Examples:

The app just became active

The app is entering the background

The app entered the background

These work fine normally but never execute when I call for "Simulate Background Fetch", even though the app does retreat to the background.

Did you ever solved it? I'm habing the same problem as you describe here.

I currently have the same issue, anyone knows a fix? Did you solved it?

I just tried again to "Simulate Background Fetch" with Xcode 8.1 (8B62) on macOS Sierra 10.12.1. No change. It crashes almost immediately like it always has. This is incredibly annoying for working on background feteches, since I have to wait about 20-30 minutes for them to trigger "naturally".


Apple marked my July bug report on this as "No Value". I have no idea what that means but it sounds like they are choosing to ignore it. I'm going to re-submit. Please do the same. https://bugreport.apple.com

Apple marked my July bug report on this as "No Value".

What was your bug number?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Simulate Background Fetch not working in Xcode 8 beta
 
 
Q