This problem is iPad specific.
When I use a WKWebView inside my app, its User Agent field is identical to the one sent by Safari. However, the page returned by Wikipedia to my App includes the standard Wikipedia side-bar. Safari on the iPad does not show the side bar.
I would like WKWebview to behave the same was as Safari. I would appreciate suggestions.
You can use SFSafariViewController instead Its behaviour is identical to Safari
if let url = URL(string: urlString) {
let config = SFSafariViewController.Configuration()
config.entersReaderIfAvailable = true
let vc = SFSafariViewController(url: url, configuration: config)
present(vc, animated: true)
}
Related
how I can open url in native inner browser in app, like this
Attention: this is not UIWebView
Try this code for swift, you can open default browser (Safari) in your APP using below code
import UIKit
import SafariServices
let url = URL(string: "https://www.google.com")
let vc = SFSafariViewController(url: url!)
present(vc, animated: true, completion: nil)
I'd like to redirect the user to the general settings page, not the application settings page (with permissions, etc.). Is that possible and if so, how?
Try this!!
let url = NSURL(string: UIApplicationOpenSettingsURLString)
if UIApplication.shared.canOpenURL(url as! URL) {
UIApplication.shared.openURL(url as! URL)
}
To navigate to specific page, check this link:
How do i open phone settings when a button is clicked ios
Try below code
UIApplication.shared.open(URL(string:"App-Prefs:root=General")!, options: [:], completionHandler: nil)
He guys. I want the website to open in reading mode. I want it to open without unnecessary ads and buttons. How can I do that on webView. Sorry for my very bad English. Thanks.
UPDATE FOR SWIFT 4, iOS 11
The SFSafariViewController init function that takes an entersReaderIfAvailable parameter has been replaced by one that takes an SFSafariViewController.Configuration property. To get the old behaviour you can replace the code used in answers above by this:
let urlString = "http://www.google.com"
let url = URL(string: urlString)!
let config = SFSafariViewController.Configuration()
config.entersReaderIfAvailable = true
let safariVC = SFSafariViewController(url: url, configuration: config)
present(safariVC, animated: true, completion: nil)
This will do the trick!
First thing you cannot enable "Reader" mode for WKWebView or UIWebView.
You need to use SFSafariViewController
Then you need to set entersReaderIfAvailable to true when initializing the instance.
Here an example :
let urlString = "http://google.com"
let url = URL(string: urlString)
let safariVC = SFSafariViewController(url: url!, entersReaderIfAvailable: true)
present(safariVC, animated: true, completion: nil)
I am trying to open a URL using Safari when the app gets a push notification. This works successfully when the app is in the first viewcontroller. But if the app is further into the program I get an error
<SFSafariViewController: 0x10b20ae60> on <AdViewController: 0x100b14530> whose view is not in the window hierarchy!
(AdViewController is my first view controller, so it is still focused on that one. )
I have searched this site and have tried all the suggestions for this error but have come up short. Currently, my code looks like this:
if MessageUrl != nil , let url = URL(string: MessageUrl!) {
let safari = SFSafariViewController(url: url)
self.window?.rootViewController?.presentedViewController?.present(safari, animated: true, completion: nil)
}
Get top most UIViewController I used extension UIApplication in Appdeleagte from the "swift 3" answer at bottom of that page and changed my code to:
if MessageUrl != nil , let url = URL(string: MessageUrl!) {
let safari = SFSafariViewController(url: url)
UIApplication.topViewController()?.present(safari, animated: true, completion: nil)
}
I'm using a SFSafariViewController. The initial url that loads redirects to another url. I need to get the current url bar that SFSafariViewController has.
It's successfully redirecting because I can see it in the url bar but I got no access not even from delegate methods.
Before that, I was using UIWebView and it worked fine but suddenly it doesn't redirect anymore.
This is my code for SFSafariViewController:
override func viewDidAppear(_ animated: Bool) {
safari = SFSafariViewController(url: URL(string:"https://api.instagram.com/oauth/authorize/?client_id=client_code&redirect_uri=http://localhost&response_type=code")!)
safari.delegate = self
self.present(safari, animated: true, completion: nil)
}
It's presenting rightly but I need access to the current url.
Thanks in advance.