Я использую Device.OpenUri(new Uri(word_doc_url));
для открытия слова / pdf do c в моем приложении. Документы PDF открываются нормально, но документы Word не открываются на устройствах ios. Отображение AccessdeniedAccess
сообщения при открытом слове do c on iPhone.
Снимок экрана
[! [Введите описание изображения здесь] [1]] [1 ]
Я добавил ключ NSAppTransportSecurity
в свой info.plist.
Снимок экрана
[! [Введите описание изображения здесь] [2 ]] [2]
Также опробовал функцию веб-просмотра для открытия слова do c в приложении согласно [этой теме] [3].
PdfWebView.cs в PCL
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 и слово файлы не отображаются в webview.