在我们当前的 Xamarin 项目中,我遇到了一个奇怪的问题。当应用程序向服务器发送更大的数据块时,为了在应用程序进入后台时保护它,我们正在启动一个长时间运行的任务(使用UIApplication.SharedApplication.BeginBackgroundTask / UIApplication.SharedApplication.EndBackgroundTask
API)。奇怪的是,当我从我的机器上构建和运行时,这很有效,但是当我的几个同事在从他们的机器上构建/部署应用程序时运行完全相同的场景时,会出现超时错误。
据我了解,在这样的长期运行任务中运行东西应该可以工作。我不应该在info.plist中指定后台功能。此外,作为发送/接收的HttpClient
雇员NSUrlSession
,当应用程序进入后台时,应该保护它免受中断,对吧?
我无法弄清楚为什么相同的代码在使用不同的 Mac 构建时会在同一设备上产生不同的行为。VS 中的某个地方是否可能存在一些影响这种行为的机器本地设置?
我现在没有想法,所以任何提示将不胜感激。
这是根据构建/部署它的 Mac 工作/失败的代码示例:
public async Task Submit()
{
// ... some irrelevant code
BackgroundTask.Run(async () => await submitAsync()); // Form-level encapsulation of the UIApplication.SharedApplication.BeginBackgroundTask API
// ... more irrelevant code
}
private async Task submitAsync()
{
if (!IsSubmitAllowed)
return;
IsBusy = true;
IsGoBackAllowed = IsGoNextAllowed = false;
var statusIndicator = new StatusIndicator();
await PopupNavigation.Instance.PushAsync(statusIndicator);
try
{
statusIndicator.Status = "Saving TI";
statusIndicator.Progress = 0.1;
var submitted = await _service.SubmitAsync(Model); // ERROR! causes timeout exception for some
var submittedId = submitted.BackendId;
// ... etc.