How to display file from remote url inside a xamarin.ios app - ios

How to display a file (pdf,txt,doc..) from remote url inside a xamarin.ios app?
i need to display a file inside a application, can anybody help me ?
Thanks in advance

Solution:
As Jason said, load your files into a webView I would show the code for you:
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.
Pay attention to the ATS setting in your app as your website begin with http instead of https.
Add the following to your app's Info.plist file to allow web pages to load correctly while Apple Transport Security (ATS) protection is still enabled for the rest of the app:
<key>NSAppTransportSecurity</key>
<dict>
<key> NSAllowsArbitraryLoadsInWebContent</key>
<true/>
</dict>
Refer: opting-out-of-ats

Related

WKWebView not loads http image in iOS 10 and above

I am loading a https URL in WKWebView and inside that few images are coming from HTTP URL which is loading perfectly fine on enabling NSAllowsArbitraryLoads in info.plist file in iOS 9. But on iOS 10 and above it is not loading the HTTP images. I read Apple and followed all possible way but no luck.
Add the below line in info.plist,
NSAllowsArbitraryLoadsInWebContent
and set its value as YES
Allowing Insecure Connection to a Single Server
fetching media from an insecure server use below
NSAppTransportSecurity
NSExceptionDomains
"media-server.example.com"
NSExceptionAllowsInsecureHTTPLoads = YES
Apple warnings
Important: Before implementing this exception, consider that a
seemingly-benign network request can cause security problems of the
sort that ATS is intended to mitigate. For example, fetching media
from an insecure server entails the following risks, among others: An
attacker can see the media file a user is accessing Your app’s attack
surface expands, for example, by allowing a bad actor to feed your app
a malicious file intended to trigger a buffer overrun Avoid this
connection type if possible.
The App Transport Security (ATS) keys are:
NSAllowsArbitraryLoads
NSAllowsArbitraryLoadsForMedia
NSAllowsArbitraryLoadsInWebContent
NSExceptionAllowsInsecureHTTPLoads
NSExceptionMinimumTLSVersion
You can get more info from NSAppTransportSecurity

Can't load http authorisation website url in webview on IOS9 with swift 2

I'm now to IOS development and i encounter a problem that i can't load a http authorisation site in webview, it just show blank page and nothing comes out, here is my code to load the website:
#IBAction func testhttp(sender: AnyObject) {
let url = NSURL(string: "http://www.obee.com.au/demo/admin/index.php");
let request = NSURLRequest(URL: url!);
//see2 is the webview....
see2.loadRequest(request);
}
Can anyone help me fix this problem ?
Cheers
It seems like it needs an authentication to load the page. You might fix it with providing credential info in the header of NSURLRequest.
How to make an HTTP request + basic auth in Swift
Add Following Line Code in info.plist:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Screen shot:
Go to your plist, Right click on Information property list click add new row then add new row as app transport security system and inside this row add allow arbitrary load as yes

iOS: SSL error - page not loading in WKWebView but loads in Safari

In the app I'm working on, I need to handle 3-D Secure redirects from our payment service provider. These redirects point to a web page of the card issuer that is shown in a WKWebView to the user in the app.
This works all the time except one case where the WKWebView doesn't load for https://3dsecure.csas.cz/ and fails with the following error:
Error Domain=NSURLErrorDomain
Code=-1200
"An SSL error has occurred and a secure connection to the server cannot be made."
What's interesting is that the same URL loads with no problems in Safari or in SFSafariViewController. Even the server's certificate is okay:
I've tried to play around with NSAppTransportSecurity settings in app's Info.plist file, specifically enable NSAllowsArbitraryLoadsInWebContent and NSAllowsArbitraryLoads but it does have no effect.
Forward Secrecy
It turns out that the server for 3dsecure.csas.cz does not support Forward Secrecy: https://www.ssllabs.com/ssltest/analyze.html?d=3dsecure.csas.cz&s=194.50.240.77
Perfect forward secrecy is required by App Transport Security in iOS9 and above for all app connections, including webviews (not including Safari, however)
ATS Debugging
Running the following command in Terminal runs ATS diagnostics and tells more about the problem and how to solve it:
/usr/bin/nscurl --ats-diagnostics --verbose https://3dsecure.csas.cz
ATS Exception in the app
Allowing the webview in the app to connect to a specific server that does not support forward secrecy could be done by adding the following in the Info.plist file:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>3dsecure.csas.cz</key>
<dict>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
</dict>
</dict>
Not future-proof
This exception needs to be added for every single domain that does not support forward secrecy. Unfortunately, It's impossible to know all the 3-d secure servers in advance as they come as redirects from the payment provider.
What I don't know is if not requiring forward secrecy could be set for any domain, globally, and just within a specific webview, without affecting the whole app.

Swift UIWebView not loading http sites

I created a web view controller and it loads https sites(ex: , ) but not http, non ssl secured sites(ex: http://bswd.us, http://www.barretthillins.com). When i do put a hhtp site in there, it does load but just a blank, white web view. How would i need to fix this?
This is due to the App Transport Security, a new protocol introduced by Apple at WWDC 2015. It doesn't allow any connections that are not HTTPS. You can disable it, however it's not recommended as it secures your app.
To disable it you have to edit the App's .plist. Simply right-click the .plist file and select Open As -> Source File and add the following code:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key><true/>
</dict>
This will allow HTTP requests.
Hope that helps, Julian.
You can also allow access to http content just through webviews, by adding this instead:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>
</dict>

NSData cannot retrive image from internet anymore [duplicate]

This question already has answers here:
How do I load an HTTP URL with App Transport Security enabled in iOS 9? [duplicate]
(8 answers)
Closed 7 years ago.
The following code works fine before iOS8.4.1 (includ 8.4.1). While it ruturns nil in iOS9.0.1. Is it a bug or there is a public annoucement for this change? I tested with two iPads.
let url = NSURL(string: "http://www.mapshots.com/wp-content/uploads/2014/05/mapshots-ag-studio-agricultural-mapping-software-logo.png")
let data = NSData(contentsOfURL: url!)
NSLog("Data length #%", (data?.length)!)
This is an issue related to ATS(App Transport Security Protocol) changes made by Apple in iOS 9. By default iOS9 disregard communication with http protocol. Your URL should be https. However you can include exception for specific domains in your app or you can allow all http communication to be allowed from within your app.
Check the Documentation for full details.
To Allow all http domains from your application, you should add
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
But as Apple has recommended these new settings, you should chose to add exception for this specific domain in your app rather than allowing all http domains. Check this thread to achieve this.
With iOS 9 you can't call an HTTP anymore because the ATS (App Transport Security) calls should be HTTPS. To work with HTTP links, you should insert the following key in the info.plist file to disable the ATS:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key><true/>
</dict>
create a new voice in the info.plist file "NSAppTransportSecurity" like dict.
insert in it the key "NSAllowsArbitraryLoads" like boolean and set to YES
;-)

Resources