如何在 xamarin.ios 应用程序中显示来自远程 url 的文件
How to display file from remote url inside a xamarin.ios app
如何在 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>
如何在 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>