I highly doubt it, but is there any way to scroll to a specific location in an SFSafariViewController? In a regular WKWebView, doing so is easy. All you need to call is [self.webView.scrollView setContentOffset:CGPointMake(0, 100)];. I've also considered trying to get the SFSafariViewController to evaluate Javascript and do it that way like WKWebViews can. If this is not possible please let me know.
According to the documentation, this is not the use case for SFSafariViewController.
The user's activity and interaction with SFSafariViewController are not visible to your app, which cannot access AutoFill data, browsing history, or website data
If you need to interact with the web view, use a web view(UIWebView or WKWebView). SFSafariViewController is meant to provide browser features within an app. You do not have control over what is going on within the view.
Related
I'm using the newest version of Xcode and Swift.
I'm using a WKWebView to load content from my web server.
You can swipe to go back and forward in the history of web pages you visited.
There's also a button to go back to the home page.
I additionally want to clear the history/backForwardList, so it's impossible to go back or forward, since this is the expected behavior when you reset the current view.
How can I do that?
As such, there is no method defined by Apple to do so but if you really wish to implement this functionality, I would suggest you just reinitialize your WKWebView.
webView = WKWebView()
I did this in my app but one thing to note is that you will have to reset all your constraints again.
Is it possible customize SFSafariViewController like:
- change "Share" button
- or add new button on same toolbar where "Share" and "Compass" buttons are
Any help will be appreciated.
No. However, you can change some specific configuration of that controller. Namely:
through SFSafariViewControllerConfiguration, you have barCollapsingEnabled and entersReaderIfAvailable.
Data for activityItemsForURL and excludedActivityTypesForURL.
preferredBarTintColor and dismissButtonStyle, etc...
Apple says:
Important
In accordance with App Store Review Guidelines, this view controller
must be used to visibly present information to users; the controller
may not be hidden or obscured by other views or layers. Additionally,
an app may not use SFSafariViewController to track users without their
knowledge and consent.
Lastly, indeed, you may use WKWebView instead for further customisation of your screen.
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.
Read doc: https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller
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 showing a twitter feed in a uiwebview... however there is a problem: it appears significantly differently in the uiwebview then what it does in mobile safari. Ultimately, I much prefer the look of the feed as it is shown in mobile safari. Is there any way to 'trick' the web view into displaying itself as safari? Possibly by altering the user agent? Thanks.
Ended up altering the user agent. App made it past apple review fine.
UIWeView and Safari doesn't display all the pages as the same..There can be minor differences in formatting in UIWebView which won't be found in Safari..
Solution to this is to use javascript to alter the WebView itself programmatically to display things right..
more info avaialble in UIWebView Class Reference doc here
I've been wondering how all the web apps display web content, say on a UITableView. When we call UIWebView instance method loadRequest: it simply surfs away to the link provided with the NSURL object. But how do we further manage all the contents with TableViews, ImageViews and so on. What is the basic principle of web apps in iOS? Do I need to learn HTML and any other web related technology like AJAX,java script etc.?
You don't display the contents of a UIWebView in a UITableView (or UIImageView, etc.) The apps you're likely referring to use one of two approaches:
Download the data using NSURLConnection, usually with REST and JSON. Then display it in a UITableView.
Display HTML content in a UIWebView that looks like a UITableView
For more information on the first case see the URL Loading System Programming Guide. For more information on the second case, see Getting Started with iOS Web Apps.
Most things that could run in MobileSafari can also run in a UIWebView. It is difficult, however, to get native, correct behavior for all your UI elements using a UIWebView. Button taps in particular do not work correctly in most web apps. Swipes also can behave non-optimally. But even so, many "apps" out there are actually just web pages in a UIWebView. (The Facebook app is a good example of this.)