如何在 xamarin.ios 应用程序内从远程 URL 显示文件(pdf、txt、doc..)?
我需要在应用程序中显示文件,有人可以帮助我吗? 提前致谢
最佳答案
解决方案:
正如Jason所说,将您的文件加载到webView
中,我将向您展示代码:
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Perform any additional setup after loading the view, typically from a nib.
var webView = new UIWebView(View.Bounds);
View.AddSubview(webView);
var url = "http://css4.pub/2015/icelandic/dictionary.pdf"; // NOTE: https secure request
webView.LoadRequest(new NSUrlRequest(new NSUrl(url)));
}
Because ATS is enabled by default in iOS 9 and OS X El Capitan, if your Xamarin.iOS app or any library or service it is using makes connection to the internet, you'll need to take some action or your connections will result in an exception being thrown.
请注意应用中的 ATS
设置,因为您的网站以 http
开头,而不是 https
。
将以下内容添加到应用的 Info.plist
文件中,以允许网页正确加载,同时仍为其余部分启用 Apple Transport Security (ATS)
保护应用程序:
<key>NSAppTransportSecurity</key>
<dict>
<key> NSAllowsArbitraryLoadsInWebContent</key>
<true/>
</dict>
关于ios - 如何在 xamarin.ios 应用程序内显示来自远程 url 的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54632496/