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

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

问题描述

我正在尝试使用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\transfers\" + 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连接到pc时,电话才连接到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.

推荐答案

您正面临背景传输策略.

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

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

这意味着当您下载/上传较大的文件时,您需要更改

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.

在您的App中,您应该在开始下载/上传文件之前检查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).

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

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