【发布时间】:2022-11-14 14:26:52
【问题描述】:
当我在调试和我的电脑上时,我有这个方法工作正常:
public void ShowPdf(byte[] pdfInfo)
{
...
Device.BeginInvokeOnMainThread(async () =>
{
var intentHelper = DependencyService.Get<IIntentHelper>();
intentHelper.File(pdfInfo);
});
}
和这样的依赖服务:
[assembly: Xamarin.Forms.Dependency(typeof(IntentHelperUWP))]
namespace myApp.UWP
{
class IntentHelperUWP : IIntentHelper
{
public async Task FileAsync2(byte[] array)
{
var baseUrl = DependencyService.Get<IBaseUrl>().Get();
StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
StorageFile pdfFile = await storageFolder.CreateFileAsync("test.pdf", CreationCollisionOption.ReplaceExisting);
//write data to created file
await FileIO.WriteBytesAsync(pdfFile, array);
//get asets folder
StorageFolder appInstalledFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFolder assetsFolder = await appInstalledFolder.GetFolderAsync("Assets");
//move file from local folder to assets
await pdfFile.MoveAsync(assetsFolder, "test.pdf", NameCollisionOption.ReplaceExisting);
Device.BeginInvokeOnMainThread(async () =>
{
Windows.System.LauncherOptions options = new Windows.System.LauncherOptions();
options.DisplayApplicationPicker = true;
options.ContentType = "application/pdf";
Windows.System.Launcher.LaunchFileAsync(pdfFile);
});
}
为什么它在使用 Visual Studio 进行调试时工作正常,但在我发布时却不行?我尝试发布和调试,查看 pdf 是否设置为内容并复制所有属性,但每次我发布和测试时,下载 pdf 的按钮什么都不做,但在我的调试中打开带有 PDF 的 Adode 阅读器。我可以做什么或测试的一些提示?
【问题讨论】:
-
添加一些异常处理和日志记录以确定发生了什么
-
我正在使用 var messageDialog = new MessageDialog(e.Message);等待 messageDialog.ShowAsync();在调试中工作正常,但在已发布的版本上,当输入“Device.BeginInvokeOnMainThread(async () =>...”时它会崩溃
-
将其记录到控制台,或使用像 appcenter.ms 这样的崩溃报告工具