Using SFSafariViewController, works well but for some reason when I go to this webpage [knowitall.ch], it starts up by opening a zoomed view? with a small black box that I need to press to get the full webpage.
My code couldn't be simpler.
if let url = URL(string: url2U) {
let vc = SFSafariViewController(url: url, entersReaderIfAvailable: true)
vc.delegate = self
present(vc, animated: true)
}
If I press the box I get the correct view, how to code around this so I open with the second view here? black box not required :)
That "zoomed view" is the Reader Mode. It shows up because you asked for it. Set entersReaderIfAvailable to false if you don't want it. Also, init(url:entersReaderIfAvailable:) has been deprecated in iOS 11. You need to initialize it with a config object:
if let url = URL(string: url2U) {
let vc: SFSafariViewController
if #available(iOS 11.0, *) {
let config = SFSafariViewController.Configuration()
config.entersReaderIfAvailable = false
vc = SFSafariViewController(url: url, configuration: config)
} else {
vc = SFSafariViewController(url: url, entersReaderIfAvailable: false)
}
vc.delegate = self
present(vc, animated: true)
}
Related
Problem:
I would like SFSafariViewController to autoplay a YouTube video in full screen.
Code:
import SafariServices
#objc func handleYTTap(_ sender: UIGestureRecognizer) {
let youtubeVideoURL = "https://youtu.be/d9MyW72ELq0"
let bookmark = NSURL(string: youtubeVideoURL)
let safari = SFSafariViewController(url: bookmark as! URL)
if(UIDevice.current.userInterfaceIdiom == .pad) {
safari.modalPresentationStyle = .fullScreen
}else{
safari.modalPresentationStyle = .fullScreen
}
self.present(safari, animated: true, completion: nil)
}
Tried Solutions:
I have tried to implement
"?playsinline=1?autoplay=1".
to the url but still cant get the SFSafariViewController to autoplay in full screen. is this even possible to do without creating a custom view or using a library of some sort?
I would like to send the signed pdf to other's email. How can I do?
My Code:
#objc func handleUploadPDF() {
let fileURL = Bundle.main.bundleURL.appendingPathComponent("Exhibit-A-SAMPLE-CONTRACT.pdf")
let writableURL = copyFileURLToDocumentFolder(fileURL)
let document = PSPDFDocument(url: fileURL)
let configuration = PSPDFConfiguration { builder in
builder.thumbnailBarMode = .scrollable
}
let pdfController = PDFViewController(document: document, configuration: configuration)
present(UINavigationController(rootViewController: pdfController), animated: true, completion:nil)
}
Make sure that you include emailButtonItem in pdfViewController's navigation item's right bar button items array, like so:
#objc func handleUploadPDF() {
let fileURL = Bundle.main.bundleURL.appendingPathComponent("Exhibit-A-SAMPLE-CONTRACT.pdf")
let writableURL = copyFileURLToDocumentFolder(fileURL)
let document = PSPDFDocument(url: fileURL)
let configuration = PSPDFConfiguration { builder in
builder.thumbnailBarMode = .scrollable
}
let pdfController = PDFViewController(document: document, configuration: configuration)
pdfController.navigationItem.setRightBarButtonItems([pdfController.emailButtonItem], animated: false)
present(UINavigationController(rootViewController: pdfController), animated: true, completion:nil)
}
For more details about how to customize the toolbar, please take a look at https://pspdfkit.com/guides/ios/current/customizing-the-interface/customizing-the-toolbar/
In the future, please reach out to our support portal at pspdfkit.com/support/request/ - we're happy to provide support there for our commercial SDK.
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 looking to use the SFSafariViewController and have it automatically load a website when the app is opened. Is this possible?
What I have so far (brand new single ios app):
// ViewController.swift
let urlString = "https://stackoverflow.com"
#IBAction func launchSFSafariViewController(sender: AnyObject) {
if let url = NSURL(string: urlString) {
let vc = SFSafariViewController(URL: url, entersReaderIfAvailable: true)
vc.delegate = self
presentViewController(vc, animated: true, completion: nil)
}
}
How do I connect the action to the main view controller via the storyboard? All the articles I see only discuss connecting a button to an action.
Implement viewDidAppear to perform the presentation. (You will need to use a Bool flag, though, to make sure this doesn't happen when you dismiss the presented view controller and viewDidAppear is called again!)