I'm trying to load an image stored in a FTP server on a webview. The problem is that using
let url = "ftp://example.com/images/image1.jpg"
let requestURL = NSURL(string:url)
let request = NSURLRequest(URL: requestURL!)
webView.loadRequest(request)
only shows a white screen because the FTP server asks for a username and password to grant access. So my question is: how can I authenticate myself so the image from the ftp url loads in the webview?
You can build the URL using this mask.
ftp://username:password#hostname/
let login = "LoginName"
let password = "Password"
let ftpServer = "ftp.server.com"
let fileName = "example.txt"
let ftpUrl = NSURL(string: "ftp://\(login):\(password)#\(ftpServer):21/\(fileName)")
Related
I don't want to write the link " https://stackoverflow.com/questions/ask" as shown in this line. I want url to receive the last copied URL from clipboard, what should I add?
let url = URL(string: "https://stackoverflow.com/questions/ask")
Copy
let url = URL(string: "https://stackoverflow.com/questions/ask")
UIPasteboard.general.string = url
Paste
if let url = UIPasteboard.general.string {
url = url
}
I have a problem with the UIWebView. I cant open a Website with Windows Authentication... In the Safari Browser a pop-up appears, therefor in the WebView Control happened nothing.
Can someone help me with this problem?
Here my code:
let url = NSURL (string: "http://inside.domain.com");
let requestObj = NSURLRequest(URL: url!);
browser.loadRequest(requestObj);
I also set the Info.plist.....
Thanks for helping
I am assuming that your username is myUserName and password is myPassword
Now modifying your piece of code
let urlComponents = NSURLComponents(string: "http://inside.domain.com");
urlComponents.user = "myUserName";
urlComponents.password = "myPassword";
let url = urlComponents.URL;
let requestObj = NSURLRequest(URL: url!);
browser.loadRequest(requestObj);
If I use the email address "appname.app#company.co.za" then it doesn't work but if I try appname#company.co.za then it works.
I've tried this from How to open mail app from Swift
let url = NSURL(string: "appname.app#company.co.za")
UIApplication.sharedApplication().openURL(url!)
and this
let url = NSURL(string: "appname.app#company.co.za".stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!)
UIApplication.sharedApplication().openURL(url!)
I've seen that you can download an image in IOS through a URL. However, this requires that the URL be public. I'd much rather do it in such a way where my application makes a request to the server and if the necessary requirements are met, the server responds with an image. I do not want my images to be visible from the web.
The easiest option is to put the password in the URL:
let url = NSURL(string: "http://exapmle.com/2XwLZAgAO2VP9JqXg1s73zmB/foo.png")
let dataOptional: NSData? = NSData(contentsOfURL: url)
if let data = dataOptional {
let image = UIImage(data: data)
} else {
println("Error loading \(url)")
}
I updated to iOS 8.1 and updated my xcode but now something is broken on with my webview.
I used this part of code:
let stream = "http://stream.hive365.co.uk:8088/live"
let url = NSURL(string: stream)
let request = NSURLRequest(URL: url)
webplayer.loadRequest(request)
xcode gives a error about the let request
value of optional type NSURL? not unwrapped; did you mean to use! or ?
I'm new with iOS swift development and can't get the error away...
any help would be appreciated!
NSURL returns an optional so you need to check if it is nil
let stream = "http://stream.hive365.co.uk:8088/live"
if let url = NSURL(string: stream) {
let request = NSURLRequest(URL: url)
webplayer.loadRequest(request)
}
change
let url = NSURL(string: stream)
to
let url = NSURL(string: stream)?
or
let url : NSURL = NSURL(string: stream) as NSURL