【发布时间】:2020-07-12 19:58:44
【问题描述】:
我正在使用Device.OpenUri(new Uri(word_doc_url)); 在我的应用程序中打开 word/pdf 文档。 Pdf 文档可以正常打开,但 word 文档没有在 ios 设备中打开。在 iPhone 上打开 word doc 时显示 AccessdeniedAccess 消息。
截图
[![在此处输入图片描述][1]][1]
我在 info.plist 中添加了 NSAppTransportSecurity 键。
截图
[![在此处输入图片描述][2]][2]
还尝试了根据 [this thread][3] 在应用中打开 word doc 的 webview 功能。
PCL 中的 PdfWebView.cs
public class PdfWebView : WebView
{
public static readonly BindableProperty UriProperty = BindableProperty.Create(propertyName: "Uri",
returnType: typeof(string),
declaringType: typeof(PdfWebView),
defaultValue: default(string));
public string Uri
{
get { return (string)GetValue(UriProperty); }
set { SetValue(UriProperty, value); }
}
}
PdfWebViewRenderer.cs
[assembly: ExportRenderer(typeof(PdfWebView), typeof(PdfWebViewRenderer))]
namespace Projectname.iOS.Renderer
{
class PdfWebViewRenderer : ViewRenderer<PdfWebView, UIWebView>
{
protected override void OnElementChanged(ElementChangedEventArgs<PdfWebView> e)
{
base.OnElementChanged(e);
if (Control == null)
{
SetNativeControl(new UIWebView());
}
if (e.OldElement != null)
{
// Cleanup
}
if (e.NewElement != null)
{
var customWebView = Element as PdfWebView;
string fileName = Path.Combine(NSBundle.MainBundle.BundlePath, string.Format("Content/{0}", WebUtility.UrlEncode(customWebView.Uri)));
Control.LoadRequest(new NSUrlRequest(new NSUrl(fileName, false)));
Control.ScalesPageToFit = true;
}
}
}
}
在 XAML 和 XAML.cs 中:
<local:PdfWebView
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
x:Name="pdf_Webview"/>
pdf_Webview.Source = pdfurl;
pdf_Webview.Uri = pdfurl;
但是 pdf 和 word 文件没有显示在 webview 中。
【问题讨论】:
-
您可以使用
QLPreviewController在您的应用程序中打开本地word文件。 -
@LucasZhang-MSFT Word 文件未保存在本地。
-
@LucasZhang-MSFT no
标签: pdf xamarin.forms webview ms-word