href tel: scheme not working in WKWebView iOS Swift 4 - ios

I am trying to wrap my website inside a WKWebView but an anchor with href="tel:312133" is not showing any action when clicked on it.
import UIKit
import WebKit
class ViewController: UIViewController {
#IBOutlet var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let mUrl = URL(string: "https://www.example.com")
let mRequest = URLRequest(url: mUrl!)
webView.load(mRequest)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

Related

A Tab's page is not shown

A Tab's page is not shown.
I wrote PhotoController like
import Foundation
import UIKit
class PhotoController:UIViewController,UINavigationControllerDelegate,UIImagePickerControllerDelegate{
#IBOutlet weak var myImageView: UIImageView!
#IBAction func PhotoSelect(_ sender: Any) {
}
#IBAction func PhotoSend(_ sender: Any) {
let myPickerController = UIImagePickerController()
myPickerController.delegate = self;
myPickerController.sourceType = UIImagePickerControllerSourceType.photoLibrary
self.present(myPickerController, animated: true, completion: nil)
}
private func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject])
{
myImageView.image = info[UIImagePickerControllerOriginalImage] as? UIImage
self.dismiss(animated: true, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//myImageUploadRequest()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
In this controller, my goal is to select photos and send them to server.
I am using TabbarController,but main storyboard which is connected with PhotoController is not shown when I run emulator.I do not know why this happen,I think at least 2 buttons are shown in there.But 2 buttons are not shown.
However,ViewController is shown when I run emulator.
ViewController is
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var webBrowser: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url = NSURL(string:"https://www.google.com")
let request = NSURLRequest(url:url! as URL)
self.webBrowser.loadRequest(request as URLRequest)
// 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.
}
}
In this controller,Google web site is shown, and it is ok.
So,I think something connection is wrong, but I cannot find the point.
My Mainstoryboard is
Mainstoryboard
Connection with PhotoController&mainstoryboard is
Connection with PhotoController&mainstoryboard
How can I fix this?

How to open Facebook and Twitter share buttons when clicking on it in a WKWebView(swift 3)?

I am actually using a WKWebView in my IOS application. The url loaded successfully but when clicking on the Facebook and Twitter share buttons nothing happens. How can I solve this issue?
Here is the following code:
ViewController:
import UIKit
import WebKit
class ViewController: UIViewController,WKNavigationDelegate {
#IBOutlet var containerView : UIView! = nil
var webView = WKWebView()
override func loadView() {
super.loadView()
self.webView = WKWebView()
self.view = self.webView
}
override func viewDidLoad() {
super.viewDidLoad()
let url = NSURL(string: "https://www.examplepage.com")!
webView.load(NSURLRequest(url: url as URL) as URLRequest)
webView.allowsBackForwardNavigationGestures = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

UIWebView UIViewController does not load URL

I am currently having this issue with IOS app.
When I click on a URL button the UIWebView loads the correct URL in first instance however when I visit another page within same Web View Frame it stores that page to its memory. When I navigate to another button and click back to previous button it shows the page that I was previously in instead of loading the URL.
What I want to achieve is when user clicks on button the UIWebView loads the URL .
My current code:
import UIKit
class MenuViewController: UIViewController {
#IBOutlet weak var oyebWebView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
oyebWebView.loadRequest(NSURLRequest(URL: NSURL(string: MenuUrl)!))
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
You can use following code it will work.
import UIKit
class MenuViewController: UIViewController {
#IBOutlet weak var oyebWebView: UIWebView!
override func viewWillAppear(animated: Bool) {
let webUrl : NSURL = NSURL(string: MenuUrl)!
let webRequest : NSURLRequest = NSURLRequest(URL: webUrl)
oyebWebView.loadRequest(webRequest);
}
override func viewDidLoad() {
// super.viewDidLoad()
//super.viewWillAppear(YES)
// self.viewDidAppear(true)
let webUrl : NSURL = NSURL(string: MenuUrl)!
let webRequest : NSURLRequest = NSURLRequest(URL: webUrl)
oyebWebView.loadRequest(webRequest);
//oyebWebView.loadRequest(NSURLRequest(URL: NSURL(string: MenuUrl)!))
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

WebView cannot scroll from top to bottom of the webpage

I have loaded a webpage to xcode WebView. But only the upper portion of the page is loaded. I can not scroll down to the bottom of the page. Same fact for pdf. Only upper 2 pages can be scrolled. What can i do ?Here is my code.
Thanks in advance.
import UIKit
class ViewController: UIViewController {
#IBOutlet var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
var URL = NSURL(string: "http://www.archetapp.com")
webView.loadRequest(NSURLRequest(URL: URL!))
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
//for pdf
import UIKit
class ViewController: UIViewController {
#IBOutlet var webViews: UIWebView!
var path = ""
override func viewDidLoad() {
super.viewDidLoad()
path = NSBundle.mainBundle().pathForResource("ibook", ofType: "pdf")!
let url = NSURL.fileURLWithPath(path)
webViews.scalesPageToFit = true
webViews.scrollView.scrollEnabled = true
webViews.userInteractionEnabled = true
self.webViews.loadRequest(NSURLRequest(URL: url!))
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
Try this!
import UIKit
class ViewController: UIViewController, UIWebViewDelegate {
#IBOutlet var webView : UIWebView
override func viewDidLoad() {
super.viewDidLoad()
//load initial
path = NSBundle.mainBundle().pathForResource("ibook", ofType: "pdf")!
let url = NSURL.fileURLWithPath(path)
var req = NSURLRequest(URL : url)
webView.delegate = self // <---
webView.loadRequest(req)
}
func webViewDidStartLoad(webView : UIWebView) {
//UIApplication.sharedApplication().networkActivityIndicatorVisible = true
println("webViewDidStartLoad")
}
func webViewDidFinishLoad(webView : UIWebView) {
//UIApplication.sharedApplication().networkActivityIndicatorVisible = false
webViews.scalesPageToFit = true
webViews.scrollView.scrollEnabled = true
webViews.userInteractionEnabled = true
println("webViewDidFinishLoad")
}
}
I had the same issue just today and at least in my case it was caused by having the "Scale Pages to Fit" option checked in the WebView properties. I'm assuming Carlos' reply regarding the zoom scale fixes it anyways but I didn't need the option enabled in the first place so that was my easy fix.

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

Resources