當我在除錯和我的電腦上時,我有這個方法作業正常:
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 閱讀器。我可以做什么或測驗的一些提示?
uj5u.com熱心網友回復:
打包后,安裝檔案夾是只讀的。您不能將檔案復制到資產檔案夾中。這在 UWP、iOS 和 Android 中都是一樣的。
您需要從創建它的應用程式資料位置啟動它,而不是嘗試將它移動到已安裝的包中。
它在除錯而不發布時有效,因為未打包的應用程式可以完全訪問其作業目錄。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/534223.html
標籤:赛马林uwp
下一篇:FileSystem.Current.OpenAppPackageFileAsync與FileSystemOpenAppPackageFileAsync
