UIWebView is displaying white screen when loading in iOS - ios

I have created only a single screen app in which when my app opens it directly redirects to the company's website url. SO i have created a single screen and uses web view and activity indicator but my app got rejected from apple store by providing a reason that white screen appears while loading web view.
// reason of rejection from app store ---
We discovered one or more bugs in your app when reviewed on iPhone and iPad running iOS 10.3.2 on Wi-Fi connected to an IPv6 network.
Specifically, the app launches to a blank white screen with no content loading.
I have tried a lot but for 2-3 seconds the white screen appears on screen. What to do please help. I am new to iOS.
// code for it
import UIKit
class ViewController: UIViewController, UIWebViewDelegate{
#IBOutlet weak var webView: UIWebView!
#IBOutlet weak var activityIndicator: UIActivityIndicatorView!
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated) // No need for semicolon
self.activityIndicator.startAnimating()
self.activityIndicator.hidden = false
}
override func viewDidLoad() {
super.viewDidLoad()
self.webView.delegate = self
let url = NSURL (string: "https://www.google.co.in/");
let requestObj = NSURLRequest(URL: url!);
webView.loadRequest(requestObj);
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func webViewDidStartLoad(webView: UIWebView) {
// self.activityIndicator.startAnimating()
// self.activityIndicator.hidden = false
}
func webViewDidFinishLoad(webView: UIWebView) {
self.activityIndicator.stopAnimating()
self.activityIndicator.hidden = true
}
}

When webview is loading content and somehow any js take time to load webview will display white screen until it complete to load that js. Check you url to browser and monitor which is the thing taking too much load time

Related

Web View not acting as UIWebView

I've scoured the internet for 3 hours now, and have just given up. I figured since no one else on this entire planet has had this problem before, maybe I should ask the stackoverflow community, and see what happens.
I'm familiar with xCode, and objective C, but am learning swift. For my first app I figured I'd build a super simple webview app that loads a page. Easy right? I can code this in about 15 seconds in objective c, and I did, it works fine. Maybe there's something I'm missing here.
When I attempt to connect the object to the UIWebView it won't connect.
import UIKit
import WebKit
class ViewController: UIViewController, WKNavigationDelegate {
#IBOutlet var webView: WKWebView!
#IBOutlet var textBox: UITextField!
override func loadView() {
webView = WKWebView()
webView.navigationDelegate = self
view = webView
}
override func viewDidLoad() {
let url = NSURL(string: "https://www.google.com")!
webView.loadRequest(NSURLRequest(URL: url))
webView.allowsBackForwardNavigationGestures = true
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Image of it not connecting. It's not connecting like it should
Change type from WKWebView to UIWebView.You have added UIWebView from object library which your are trying to connect to a WKWebView object so it will not connect. WKWebview has to be added programmatically as it is not present in object library.
These two classes have similar functionalities but they are not connected to each other in anyway.
You can use the following code to build a webView app that loads a page.
import UIKit
class ADKWebViewDemoViewController: UIViewController {
#IBOutlet weak var webview: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
webview.loadRequest(NSURLRequest(URL: NSURL(string: "https://www.google.com")!))
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

webview doesn't show URL

I am new to iOS development, i am trying to use a UIWebView using the following code
import UIKit
class SecondViewController: UIViewController {
#IBOutlet var myWebView: UIWebView!
#IBOutlet var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let url = NSURL (string: "http://www.chrisharrisracing.com/twitterapp.php");
let requestObj = NSURLRequest(URL: url!);
myWebView.loadRequest(requestObj);
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
However when I build the the web page is not displayed, although when I go to the web address in a browser the page works fine, any help would be appreciated
I just created a sample project to check your issue and its working for me.
class ViewController: UIViewController {
#IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url = NSURL (string: "http://www.chrisharrisracing.com/twitterapp.php");
let requestObj = NSURLRequest(URL: url!);
webView.loadRequest(requestObj);
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
If you want you can download the sample project from the following link
https://www.dropbox.com/home/SAMPLE%20GIT%20PROJECTS%20%5BSHARED%5D/WEBVIEW?preview=webViewSample.zip
You should add NSTransportSecurity to info.plist
HOPE THIS HELPS.....
I made a sample project with your code and it works just fine. The only difference is that I didn't use the second outlet (#IBOutlet var webView: UIWebView!) you have in this code. My guess is you haven't added any constraints for your webview and that's why you can't see it. So go to your storyboard choose your webview and then go to the triangle icon at the bottom right and choose Add missing constraints.
Of course make sure your internet connection is ok and that you have added the allow arbitrary loads key in your info.plist
Maybe you haven't added your constraints yet, which is why myWebView might not be visible. Or maybe, this is probably a longshot, but I've noticed that you have another unused UIWebView called webView. Maybe, just maybe, webView is covering up myWebView, thus you aren't seeing myWebView loading the page.

XCODE swift - webview can't open ics link - in safari it works

I've made in Swift a webview & in that webview there are links to ics file on the same domain of the webview. Now, when you click this link in Safari, you can perfectly add this to your calendar, but when I try this in iOS simulator, or on my device, I can't 'open' the ICS file link.
Any idea what I am doing wrong? Thanks!
This is my code:
import UIKit
class FirstViewController: UIViewController {
#IBOutlet weak var webAgenda: UIWebView!
#IBOutlet weak var activityagenda: UIActivityIndicatorView!
var url = "http://******.be/agenda.php"
func loadURL () {
let requestURL = NSURL(string: url)
let request = NSURLRequest(URL: requestURL!)
webAgenda.loadRequest(request)
}
override func viewDidLoad() {
super.viewDidLoad()
loadURL()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func webViewDidStartLoad(webView: UIWebView) {
activityagenda.hidden = false
activityagenda.startAnimating()
}
func webViewDidFinishLoad(webView: UIWebView) {
activityagenda.hidden = true
activityagenda.stopAnimating()
}
because you load a http site so in iOS9 will have problem with App Transport Security.
disable ATS here

UIWebView not loading web page

I've been trying to learn iOS development with Swift but I've been stuck trying to load a simple web page for a week or so. I've looked all around and the following code seems to work for others but when I run the iOS simulator nothing shows up but the background for the UIWebView.
class ViewController: UIViewController {
#IBOutlet weak var myWebView: UIWebView!
let myURL = NSURL(fileURLWithPath: "https://www.google.com")
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
myWebView.loadRequest(NSURLRequest(URL: myURL!))
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
You should be using this
let myURL = NSURL(string: "https://www.google.com")
not fileURLWithPath:.
The issue is that, by using fileURLWithPath:, the web view searches the filesystem for a file named "https://www.google.com" and doesn't find one, as no such file exists.

UIWebview always loading with horizontal scroll

Im crating a simple wrapper, however no matter what device I test a website with loading it into a webview its always a bit to wide and has horizontal scrolling. I can turn that off by changing the content size but then i just cut off part of the view on the right hand side.
import UIKit
class ViewController: UIViewController, UIWebViewDelegate {
#IBOutlet var webView: UIWebView?
let endpointURL : String = "http://www.google.com/"
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
webView?.delegate = self
var url : NSURL = NSURL(string: endpointURL)!
var request : NSURLRequest = NSURLRequest(URL: url)
webView?.loadRequest(request)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func webViewDidStartLoad(webView: UIWebView) {
}
func webViewDidFinishLoad(webView: UIWebView) {
//webView.scrollView.contentSize = CGSizeMake(webView.frame.size.width, webView.scrollView.contentSize.height)
}
}
Use webView.scalesPageToFit = true
This should size the web page to fit the size of the UIWebView.
I suspect your problem might be related to the frame of the WebView.Try resizing your webview to your screen bounds.
webView.frame = UIScreen.mainScreen().bounds

Resources