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);
Related
let url = NSURL (string: "https://i.stack.imgur.com/0LSmY.jpg");
let webViewInst: UIWebView = UIWebView()
let requestObj = NSURLRequest(url: url! as URL)
webViewInst.frame = self.view.bounds
webViewInst.loadRequest(requestObj as URLRequest);
webViewInst.delegate = self
webViewInst.scalesPageToFit = true
webViewInst.contentMode = .scaleAspectFit
self.view.addsubview(webViewInst)
This is working, but we need to scroll the webview to see full image in the web page. How to fix this?
How to show the full image fit to the view?
P.S, the image that mentioned in the above url is more than 3000 pixel in diomensions(3024x4032)
Try this one I have implemented it and working as you expected.
webView = WKWebView(frame: self.view.frame)
let urlString = "https://i.stack.imgur.com/0LSmY.jpg"
let url = URL(string: urlString)!
let request = URLRequest(url: url)
webView.load(request)
self.view.addSubview(webView)
self.view.sendSubview(toBack: webView)
Hello when I use WKWebView codes with Swift 3 gives me this error
'URLRequest'; did you mean to use 'as' to explicitly convert?
I think this is bug I need help or ideas ? My codes under below
Thanks
import UIKit
import WebKit
class SocialsViewController: UIViewController, WKNavigationDelegate {
var webView = WKWebView()
override func viewDidLoad() {
super.viewDidLoad()
let url = NSURL(string: "https://facebook.com")!
webView.loadRequest(NSURLRequest(url: url))
webView.allowsBackForwardNavigationGestures = true
}
}
Use URL and URLRequest instead:
let url = URL(string: "https://facebook.com")!
webView.load(URLRequest(url: url))
This is quite similar to https://stackoverflow.com/a/37812485/2227743: you either use NSURL and have to downcast it as URL, or you directly use the new Swift 3 structs.
If you follow the error message, your example would become:
let url = NSURL(string: "https://facebook.com")!
webView.load(URLRequest(url: url as URL))
It could be even worse:
let url = NSURL(string: "https://facebook.com")!
webView.load(NSURLRequest(url: url as URL) as URLRequest)
All this works but of course it's much better to start using URL and URLRequest in Swift 3, without using all this downcasting.
Try this one
let myUrl = URL(string: "https://facebook.com")!
webView.loadRequest(URLRequest(url:myUrl));
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
class MainViewController: UIViewController, UIWebViewDelegate, MFMailComposeViewControllerDelegate {
#IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad();
webView.delegate = self;
let url = NSURL (string: "http://test.raphaels.com/mobile/");
let requestObj = NSURLRequest(URL: url);
webView.loadRequest(requestObj);
}
}
This piece code of works perfectly fine on non-secure server(URL) on iOS simulator, thats iPhone simulator/emulator on Xcode. But when I use the above URL(can only be accessed from intranet). It asks for username/password in browser and stops in iPhone emulator. Please help me, how can i supply username and password. I searched on internet and found many examples, unfortunately none of them was in swift programming.
I tried to write a solution which fails, so below is the failing code
override func viewDidLoad() {
super.viewDidLoad();
webView.delegate = self;
let username = "username11";
let password = "password22";
let loginString = NSString(format: "%#:%#", username, password);
let loginData: NSData = loginString.dataUsingEncoding(NSUTF8StringEncoding)!;
let base64LoginString = loginData.base64EncodedStringWithOptions(nil);
// create the request
let url = NSURL (string: "http://test.raphaels.com/mobile/");
let request = NSMutableURLRequest(URL: url)
request.HTTPMethod = "POST"
request.setValue("Basic \(base64LoginString)", forHTTPHeaderField: "Authorization")
webView.loadRequest(request);
}
And it worked :-) With below piece of code.
override func viewDidLoad() {
super.viewDidLoad();
webView.delegate = self;
let urlComponents = NSURLComponents(string: "http://test.raphaels.com/mobile/");
urlComponents.user = "username11";
urlComponents.password = "password22";
let url = urlComponents.URL;
let requestObj = NSURLRequest(URL: url!);
webView.loadRequest(requestObj);
}
Objective C version
NSURLComponents *urlComponents = [NSURLComponents componentsWithString:#"http://test.raphaels.com/mobile/"];
[urlComponents setUser:#"username11"];
[urlComponents setPassword:#"password22"];
NSURL *url = [urlComponents URL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
A quick and easy solution is: use URL as
http://username:password#test.raphaels.com/mobile/
No need for any special code.
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)")
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