Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

xcode - 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. :-(

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...