I'm trying to use a SFSafariViewController in the background to interact with cookies from a website. It seems that the pages is not loaded when the controller is not visible. Is that how it should be? What ways do I have to fix except than making sure the controller is always visible?
Related
I'm working on an app where there is a modal view containing a WKWebView. The webpage I'm displaying in the WKWebView is loaded via self.webView.loadHTMLString but the loading process takes too long, 5 seconds at times, and I would like to cut this time down significantly. Is there a way to preload this webpage (using loadHTMLString) so that when the modal is presented, the webpage is already loaded?
I've looked at all of the similar posts on Stack Overflow and none of them work in my case. The ways I've considered going about this are via caching and via calling setNeedsLayout in the viewDidLoad of the view controller that will present the modal, but haven't had any success. Any help would be greatly appreciated.
Is there any way to hide the share option in Safari View Controller, which is coming by default?. I am trying to hide the extra options which are given by default with the Safari View Controller but not able to do so.
Let me know if anybody knows about this.
Thanks!
SFSafariViewController is not meant for customizations. Even Apple documentation says to use WKWebView if you want to customise the look and feel of safari view controller.
From Apple documentation
Choosing the Best Web Viewing Class
If your app lets users view websites from anywhere on the Internet,
use the SFSafariViewController class. If your app customizes,
interacts with, or controls the display of web content, use the
WKWebView class. When you adopt SFSafariViewController and a user
presses a link to peek at and then pop to the link’s destination, the
user views web content from within your app. Tapping Done, the user
returns to the view controller that was displayed before the web
content was loaded. When you instead use the WKWebView class, Peek and
Pop sends the user to Safari by default.
On the other hand, SFSafariViewController does provide some kind of UI customization. You can only change the preferredBarTintColor and prefererredControlTintColor. iOS 11 has new option to set initial configuration by using #NSCopying var configuration: SFSafariViewController.Configuration { get } but sadly that will not help you either
I am working on a small app to learn WKWebView abilities. I have added a navigation bar at the bottom with back and forward buttons in order to navigate between loaded pages. But if I initialize the view with loadHTMLString instead of loadRequest, then the history buttons are not working. The canGoBack/canGoForward attribute is false.
Is it possible to navigate between loaded html documents in WKWebView if they were loaded with loadHTMLString?
Judging by the documentation, the built in history that ships with WKWebView supports URLs but not blobs of HTML. Have a look at WKBackForwardListItem. It has three properties: title, URL, and initialURL.
You could build this functionality yourself, by implementing a similar list and a similar model. I don't know if WKBackForwardListItem is subclassable, but you can make your own.
I am working on an app in which there are several screens and each screen has the same layout, just different data passed in, then I want the user to be able to swipe from one screen to the next.
So far I got something working using the UIPageViewController project template using the transition style UIPageViewControllerTransitionStyleScroll. What I have done so far works ok, although its resource intensive because it instantiates a new view controller each time I swipe to a new page but I am loooking into working around that.
The thing I am concerned about is that it is not strictly a page application in the sense of ibooks so even though I am able to make it look like a scrolling app, using the transition style setting, I wonder if there is a reason why people seem to only use this template for book type apps, unless I am mistaken
Also there seems to be an alternative approach of using a UIScrollView and PageControl to do similar functionality
http://developer.apple.com/library/ios/#samplecode/PageControl/Introduction/Intro.html
I am not sure which approach is better to solve the problem I am trying to fix, so am looking for some feedback. Each page will need to be a separate instance of a view controller as there are several elements to display on each page.
Using UIScrollView is much more difficult. If you're targeting iOS 6 you should almost certainly use UIPageViewController. If you're targeting iOS 5 then UIPageViewController might not be perfect because the only page transition available is "scroll" which looks like a page flip.
If you're worried about the resource usage, you can reuse view controllers.
See the WWDC 2012 session 223:
https://developer.apple.com/videos/play/wwdc2012/223/
I'm working on an app that has a series of hierarchical UITableViewControllers, until you are eventually taken to a UIWebView that contains the information you're looking for. It works fine except that when the UIWebView loads it takes a while to render and flashes white before loading (All my views, including the UITableViewControllers and HTML files, have a black background)
Once the UIWebView has been both loaded and displayed it's not so much a problem- I have it load up an empty HTML page with a black background while it loads the content- but the first time it's always slow, and gives me the white flash.
I've tried to pre-render the UIWebView by initializing it and loading it while the previous UITableViewController is still active, but it doesn't seem to work. It lets me define all the necessary parameters, but calling the loadView method, nor anything else I've tried, has cajoled it into actually loading up that black background HTML before it pushes the UIWebView on screen.
Ideally what I'd like it to do is just initialize the UIWebView in the background once the app starts, such that by the time it gets pushed onto the navigation stack for the user to see, it's already preloaded with that black background so there's no white flash.
How about webview.backgroundColor = [UIColor blackColor];?
Did you find and answer to this. I am doing the same thing. I have found I can create a second webview and start populating it off screen. I use javascript to check on the progress, so that I know it has rendered. However about 3 seconds after I have two pages rendered (one visible and one not) it thread for web pages crashes.
My next idea is to make both screen visible just most the unused screen a mile off to the right so the end user can't see it.