If I have an iOS app, how can I open a browser view inside the app (upon the user tapping a button) which contains no cookies from any domains?
This means the browser view should not remember cookies from the previous time the user opened the browser, nor share cookies with the Safari app.
There are now three classes to do web views as far as I understand, SFSafariViewController, WKWebView and the dated UIWebView. Which of these allows what I want to achieve?
WKWebView is the way to go. Upon initialisation it won't contain any cookies from previous sessions. From the Apple documentation:
Each web view is given its own Web Content process until an implementation-defined process limit is reached; after that, web views with the same process pool end up sharing Web Content processes.
Furthermore, WKWebView is intended as a replacement for the older UIWebView.
SFSafariViewController shares cookies and other website data with Safari.
Related
I develop a mobile app using SFSafariViewController to present a website, wherein visited links are styled using the CSS :visited pseudo-class (https://developer.mozilla.org/en-US/docs/Web/CSS/:visited).
As long as the user remains within a single SFSafariViewController session, styling visited links works fine. But as soon as the user exits back to the app, SFSafariViewController appears to "forget" which links the user had visited, such that upon returning to the site within SFSafariViewController, none of the previously visited links trigger the :visited pseudo-class, are are thus not styled as visited links.
Is this normal behavior for SFSafariViewController? Chrome Custom Tabs, used in the Android version of the same app, exhibits what I would consider "normal" behavior by remembering visited links between its session on the site in question, as does the Safari mobile browser on the same site.
I have Googled this problem and have come up empty. Of course, having worked with SFSafariViewController, I have also thoroughly read Apple's developer documentation on 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 (Overview).
Is it possible to share IndexedDB stores and data between a progressive web app (PWA) and stand-alone Safari on iOS? If so, what steps do I need to take to share the stores/data?
My use case is that I have a would-be PWA that uses third party authentication. The normal behavior is that when navigating to the third party authentication page, the PWA automatically opens the page in a new Safari window since it is out of scope. I would like to save the authentication token in IndexedDB from this Safari instance, open my PWA, and then load the token from IndexedDB in my PWA.
I have tested this implementation. It works fine (ie I can read the token from IndexedDB) in Safari standalone, but when I navigate back to my PWA and attempt to read the data, it doesn't exist. This suggests that the stores cannot be shared, but I am looking for a more definitive answer. I find no indication one way or the other in internet searches.
Note: local storage, session storage, and cookies are not shared between Safari and PWAs on iOS, so those solutions do not work which necessitated the use of IndexedDB
Rather than opening a new tab, you can use a pop up, like how it has been beautifully explained here with example and source code.
The key idea used here is window.postMessage, which allows windows and frames to send data across domains to one another.
I implemented Safari View Controller in iOS app, but is there a way to send some data from javascript of opened site to main iOS app.
I am opening my web app in the Safari VC.
You cannot do this. from Apple Guideline and i quote.
The view controller includes Safari features such as Reader, AutoFill,
Fraudulent Website Detection, and content blocking. It shares cookies
and other website data with Safari. The user's activity and
interaction with SFSafariViewController are not visible to your app,
which cannot access AutoFill data, browsing history, or website data.
You do not need to secure data between your app and Safari
As per Apple documentation ,Support Universal Links , we can move control from Safari to App using Universal Links.
In my app, when user is in doing some actions in web pages, only for particular action I want to move control from Safari to my App. Then I want to do some action in App and then again want to move control to Safari's web page, from where I had moved control to App , with output data that got generated in App by using web service.
I know user can go back to Safari from App by clicking on breadcrumb button in the status bar. But I want to achieve this programatically.
How can I achieve this.
Just use openURL in your app to open the web page you want to return to in Safari. The Universal Link will not be in effect in this case, since you're in your app and iOS will correctly deduce you just want to open Safari.
configuring Universal Links does not require you to include the query part, which means you can still use it to pass data (in both ways)
You registered http://acme.com/foo/bar in your apple-app-side-association
You can use openURL to open http://acme.com/foo/bar?data=xxx and your webpage can process the data in the query part of the URL
Let's say I have a web app that calls out to a native app via a custom URL scheme, and after the native app has done its thing it returns to my web app by opening a callback URL.
This all works fine when my web app is running in Safari. But what happens if a user saves the web app to the home screen (creating a "Web Clip")? In that case it runs in a separate process from regular safari, and has separate cookies and cache.
So when the native app tries to return to the web app, the URL will presumably get opened by Safari, not by the Web Clip, and the session will be lost. (And not just the session -- all the page state, which in a rich Javascript-based web app can be a lot of stuff with non-trivial startup time.)
Is this assumption correct? And if so, is there any way around it? Is there some way to get iOS to try to open the URL with a web clip if installed?
In order to have something launch via a custom url scheme on iOS, you must have an application register this information via the Info.plist built into the app.
It is not possible to have a webapp/webclip register this information system-level.
So, to answer your main question, you cannot do this.
Here is the information on implementing custom URL schemes in native applications.