iOS:UIBackgroundFetch - 未调用PerformFetch

时间:2015-03-26 11:08:31

标签: c# ios iphone xamarin.ios xamarin

我想在后台更新我的应用,所以我添加了必需的背景模式" fetch"到我的info.plist。 在我的FinishedLaunching中,我补充道:

UIApplication.SharedApplication.SetMinimumBackgroundFetchInterval (UIApplication.BackgroundFetchIntervalMinimum);

并覆盖方法PerformFetch:

public override void PerformFetch (UIApplication application, Action<UIBackgroundFetchResult> completionHandler)
{
    Console.WriteLine ("PerformFetch called...");

//Return no new data by default
var result = UIBackgroundFetchResult.NoData;
...

completionHandler (result);
}

但该方法永远不会被调用...... :(

问题是什么,我找不到任何错误?谢谢你的帮助。

2 个答案:

答案 0 :(得分:4)

不幸的是,系统在调用此处理程序时解决了自身问题,这是一个不可预测的事件。 而且你永远不会确定一定的执行时间。 最近,我调查了它,真的很不高兴。 早期,模拟器允许直接模拟呼叫。

答案 1 :(得分:2)

在iOS设备上,操作系统会无法预测此方法。调用此方法的频率有很多因素,包括您如何配置间隔以及应用程序执行后台提取通常需要多长时间。如果您经常花费很长时间来执行提取,操作系统将不经常调用此方法。请参阅此处“以机会性方式获取少量内容”部分:

https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

以及此处的API参考:

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/index.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:performFetchWithCompletionHandler

如果您在模拟器中测试您的应用,则可以使用Run - &gt;模拟Xamarin Studio菜单中的背景提取。模拟iOS背景提取。如果您需要根据某些外部事件可靠地启动下载,请考虑使用设置了“content-available”标志的推送通知。请参阅第一个链接中的“使用推送通知启动下载”部分。

相关问题