即使configuration了正确的后台模式,iOS后台提取仍然无法正常工作

我的应用程序具有背景模式启用后台提取检查,我validation了plist包括适当的获取模式。

我也configuration了如下的时间间隔:

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

我已经添加了处理程序如下:

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

我试着去debugging – >模拟后台提取,但不pipe它从来没有进入performFetchWithCompletionHandler 。 我也尝试运行该应用程序下的“启动由于后台提取事件”选项检查。 在此模式下运行只需在模拟器中像往常一样启动应用程序,而不调用performFetchWithCompletionHandler

有任何想法吗?

谢谢!

编辑:这似乎是影响我的应用程序的发行版本以及它可能不被隔离到模拟器。 我正在运行Swift 1.2。

编辑2:我的错误报告刚刚closures,因为它是另一个错误报告概述相同的问题的副本。 目前还没有确认这个问题是孤立的模拟器的信息。

编辑3:没有提到Xcode 6.4 Beta 2发行说明中的​​修复。 🙁

这是我发现testing背景获取的唯一方法。

  1. 编辑你的计划
  2. select运行
  3. select选项
  4. 选中“由于后台获取事件启动”选项
  5. 插入你的iOS设备并运行它的应用程序。 它不适用于iOS模拟器。

步骤2-4的视觉

查看XCode发行说明: https : //developer.apple.com/library/ios/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html

“Xcode菜单命令Simulator Background Fetch不起作用。

请改用iOS Simulator中的菜单命令。 (20145602)”

您可以通过休斯顿创build自己的背景获取推送通知给您的真实设备

  1. 安装休斯敦:打开terminal应用程序,并使用sudo gem install houston
  2. 为您的应用程序创buildPEM证书生成.pem文件用于设置Apple PUSH通知
  3. 从中获取设备标记

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData)

  1. 运行terminal并使用

对于通常的推送通知: apn push "<your_device_token>" -c /path/to/apple_push_notification.pem -m "Hello from the command line!"

用于后台提取推送通知: apn push "<your_device_token>" -c /path/to/apple_push_notification.pem -n

更多的选项为apn应用程序:

  c.option '-m', '--alert ALERT', 'Body of the alert to send in the push notification' c.option '-b', '--badge NUMBER', 'Badge number to set with the push notification' c.option '-s', '--sound SOUND', 'Sound to play with the notification' c.option '-y', '--category CATEGORY', 'Category of notification' c.option '-n', '--[no]-newsstand', 'Indicates content available for Newsstand' c.option '-d', '--data KEY=VALUE', Array, 'Passes custom data to payload (as comma-delimited "key=value" declarations)' c.option '-P', '--payload PAYLOAD', 'JSON payload for notifications' c.option '-e', '--environment ENV', [:production, :development], 'Environment to send push notification (production or development (default))' c.option '-c', '--certificate CERTIFICATE', 'Path to certificate (.pem) file' c.option '-p', '--[no]-passphrase', 'Prompt for a certificate passphrase' 

Xcode 8.3.2中,这个问题不存在。 debugging – >模拟后台抓取工作。 它甚至可以在模拟器上工作。