iOS - Enable Private Browsing in WebView - ios

I want to show private browsing mode like safari with the help of UIWebView. I want to show the same UI as Safari has for private browsing. Screenshot attached.
I have tried to use web view configuration to nonPersistent for websiteDataStore. But it will only help to not store the data.

According to the NSHTTPCookieStorage docs, cookies are not shared
between applications:
Yes, UIWebView does have the private browsing mode by default. The
Cookie data is accessible by the App only.
NSHTTPCookie's singleton instance stores the Cookie information of
the UIWebView. You may need to use deleteCookie: method to clear the
cached data
I totally agree with #Scriptable For UI like Safari you need to
design as per your requirements

Related

How to prevent reload on Tizen Public Preview Deeplink?

I'm writing a web app for Tizen Smart TV. One of the required features is implementing the Smarthub Public Preview deeplinking.
I have setup the app to open at a specific content when the Public preview tile is clicked. However, I cannot prevent the app to reload. The documentation mentions adding the appcontrol event to the window event listeners, but I don't think this event is being recognized by the app, since the code is not executed.
It only works if I directly add my deeplink() method to the onload property.
According to documentation, this piece of code should prevent the app to reload, but it is not working:
<tizen:app-control>
<tizen:src name='index.html' reload='disable'></tizen:src>
<tizen:operation name='http://samsung.com/appcontrol/operation/eden_resume'></tizen:operation>
</tizen:app-control>
window eventListener is not working wither:
onload="window.addEventListener('appcontrol', deepLink)"
Any help on how to implement this correctly?
Thank you in advance
You are probably modyfing window.location in the app (ie in router).
reload='disable' prevents reloading index.html. When application receives app control request and page is different, application will be reloaded.
You can find more about appcontrol in Tizen documentation (note that Tizen for TV may differ from other devices):
https://docs.tizen.org/application/web/guides/app-management/app-controls/
I've got some information regarding your question.
To do application resume without Page reload,
Set extra data in app-control like below
key: SkipReload
value: Yes

Xamarin.Forms WebView, WKWebViewConfiguration, and Sending "Mobile" Headers

I'm getting back into Xamarin.Forms, and I've discovered a new behavior of iOS 13 Safari on the iPad called "Desktop-Class Browsing." It's covered in detail here:
https://developer.apple.com/videos/play/wwdc2019/203
The problem for me is that I need my Web application to be able to detect if a normal Web browser is viewing it or if it's being viewed by a Xamarin.Forms.WebView. From my Web application, I used to be able to detect a Web view with the user-agent string or with the X-Requested-With header. But if my Web view is running on an iPad on iOS 13, it will enter desktop mode, which yields a desktop Safari user agent a no X-Requested-With header, and I can no longer detect that it is a Web view. This is referenced at 2:56 in the above video.
In a native iOS application, I can apparently use WKWebViewConfiguration to control these desktop-like featuers:
https://developer.apple.com/documentation/webkit/wkwebviewconfiguration
I think this is demonstrated at 9:01 in the video in my first link.
How can I use WKWebViewConfiguration with Xamarin.Forms? I see a WebKit.WKWebViewConfiguration class, but how can I utilize it with Xamarin.Forms.WebView?
Unless you follow the steps in this article, your app is using UIWebView instead of a WKWebView
There are several ways of getting access to editing the WKWebViewConfiguration:
You can use a "Custom Renderer" to implement your own WKWebView as shown in this Official Xamarin Forms example, and edit the WKWebViewConfiguration there.
Another possible way that I haven't tried- You can also implement a WKWebView inside your forms using the steps mentioned here. And then just edit that property.

Is there a function in ios webview like setCacheMode in android webview?

What feature should I use to allow iOS Webview's web content to be cached only for in the expired time in the server's meta data? I can't find keywords.
In Android Webview I solved it with setCacheMode (default).
Please WBWebKit instead of Webview.
it will give you access for cache setting using the following code:
webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);

Sync cookies in multiple WKWebViews on iOS 9

I am using 2 ViewControllers with 2 WKWebViews.
The WebViews use a shared WKWebViewConfiguration.
extension WKWebViewConfiguration {
static var Shared : WKWebViewConfiguration{
if sharedConfiguration == nil{
sharedConfiguration = WKWebViewConfiguration()
sharedConfiguration.websiteDataStore = WKWebsiteDataStore.default()
sharedConfiguration.processPool = WKProcessPool()
}
return sharedConfiguration
}
private static var sharedConfiguration : WKWebViewConfiguration!
}
I am passing this on each webView and from what I read this should be the solution for shared Cookies.
But because I am doing a login though the webContent I want to have the webViews SYNCHED if the user is logged in or not.
The problem happens when the user logs in. The steps that I follow are the :
1) I have identify the host and the path, and checking the navigationAction.request.url.host and navigationAction.request.url.path
when the user makes a request, and the request happens ONLY if the credentials are correct (So I know the correct host and path) I create a bool var that indicates that the users has logged in
2) After the WebView didFinish : FINISH , I call a func that reloads the webViews that have to get refreshed but the WebViews are not acting like they have the cookies.
3) after some seconds(different everytime) ,adding manual the code .reload() the web views in each preview , the webViews are synched.
I am working on iOS 9 since these are the requirements.
It looks that the cookies are asynced, and eventually they arrive to the shared processPool or websiteDataStore from my understanding.
Anyone have a solid solution?
You don't need to share same web configuration, you just need to share processPool and KWebsiteDataStore.default() after creating each webview configuration. To verify you can check cookies from Safari developer tool.
As #PS mentioned no workaround is working for him to sync cookies. I also encounter the same problem. but I tried some unexpected things to fix this issue and that is work 100%
Cookie sync takes some time to sync with cookie store for wkwebview. so my fix is just made dummy web request that will sync cookie on app start and after that, wherever you have to use your sign In or Sign Out call you can use without making any further modification.

Webpage cookies are not detected by UIWebView

I am developing iOS app that loads a webpage using UIWebView
The web page sets four cookies:
Two for Google Analytics, _ga and _gat
One for my web application unique vistors counter
One for my webpage to detect whether user has voted or not.
If this cookie available then display the poll results.
From Firefox's Storage Inspector I see all my cookies as expected, see screenshot:
However, from iOS I printed NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies from inside webViewDidFinishLoad and there is only two of four expected cookies, also iOS users can vote as many times as they wanted because cookies are not detected (or not stored in iOS device):
if let cookies = NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies {
for c in cookies {
print("*******************")
print("name: \(c.name)")
print("domain: \(c.domain)")
print("value: \(c.value)")
print("path: \(c.path)")
print("expiresDate: \(c.expiresDate)")
}
}
Why my iOS app does not detect my custom cookies and only detects my Google Analytics ones?
NOTE 1: I have also added this code to my app:
func applicationDidBecomeActive(application: UIApplication) {
NSHTTPCookieStorage.sharedHTTPCookieStorage().cookieAcceptPolicy = NSHTTPCookieAcceptPolicy.Always
}
NOTE 2: My backend is SharePoint web application
A few ideas:
The device's Safari "Block Cookies" settings override any changes to the cookieAcceptPolicy. The default policy of this setting on the device is "Allow from Websites I Visit," which depending on your iOS device's version, allows third-party cookies. Testing with iOS 9.3.x shows that third party cookies are persisted in a UIWebView with the default settings, but do not persist with the settings "Allow from Current Website Only" or "Always Block."
Check if the device persists your cookie with the different Safari cookie settings.
Additionally, does your cookie have an expiration date set? I've found that cookies without an expiration date set are treated as session cookies in a UIWebView, which only persist with the lifecycle of the web view that received it.

Resources