LiveConnectClient.BackgroundUploadAsync,当手机未连接到 USB 时不起作用 [英] LiveConnectClient.BackgroundUploadAsync, is not working when phone not connected to usb

查看:16
本文介绍了LiveConnectClient.BackgroundUploadAsync,当手机未连接到 USB 时不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 wp8 中使用 LiveConnectClient.BackgroundUploadAsync 来上传一些数据的副本.

I'm trying to use LiveConnectClient.BackgroundUploadAsync in wp8, to upload copy of some data.

她是我的代码:

var progress = new Progress<LiveOperationProgress>();
progress.ProgressChanged += progress_ProgressChanged;
try
{
   LiveOperationResult res = 
        await liveClient.BackgroundUploadAsync(folderID,
              new Uri(@"shared	ransfers" + backupFile.Name, UriKind.Relative),
              OverwriteOption.Overwrite, new System.Threading.CancellationTokenSource().Token, progress);
   dynamic result = res.Result;
   fileID = result.id;
}
catch (Exception ex)
{
    System.Diagnostics.Debug.WriteLine(ex.Message);
    progress.ProgressChanged -= progress_ProgressChanged;
}

它在模拟器上运行良好,但是当我在手机上尝试它时,它只有在手机通过 USB 连接到电脑,手机连接到 wifi 时才能工作.

It's working fine on emulator, but when I tried it on the phone its working only when the phone connected to pc by usb , the phone connected to wifi.

推荐答案

BackgroundTransfer 政策.

操作系统对与文件大小、连接速度和设备资源相关的后台传输实施了许多限制.

The operating system enforces a number of restrictions on background transfers related to file size, connection speeds, and device resources.

这意味着当您下载/上传较大的文件时,您需要更改TransferPreferences - 例如,如果您想上传大于 100 Mb 的文件,您将能够这样做,但只能通过 WiFi 和当手机连接到外部电源时.

Which means that when you download/upload larger files you need to change TransferPreferences - for example if you want to upload a file larger than 100 Mb you will be able to do that, but only via WiFi and while Phone is connected to external power source.

在您的应用程序中,您应该在开始下载/上传之前检查 WiFi 连接和电源,然后通知用户他应该(例如)打开 WiFi 以对如此大的文件进行操作.

In your App you should check for WiFi connection and power supply before starting downlod/upload and then inform the User that he should (for example) turn WiFi on to perform operation on such a big file.

您可以选择:

// small files but via 3G and on Battery
liveClient.BackgroundTransferPreferences = BackgroundTransferPreferences.AllowCellularAndBattery;

// larger files via WiFi, on Battery
liveClient.BackgroundTransferPreferences = BackgroundTransferPreferences.AllowBattery;

// huge files but only WiFi and External power
liveClient.BackgroundTransferPreferences = BackgroundTransferPreferences.None;

默认设置是 none - 所以如果你没有改变它,你的应用程序将等待外部电源和 WiFi - 这可能是它在通过 USB 连接时工作的原因(外部电源).

The default setting is none - so if you hadn't changed it, your App will wait for external power and WiFi - that is probably why it is working while connected via USB (external power).

这篇关于LiveConnectClient.BackgroundUploadAsync,当手机未连接到 USB 时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆