Cookies in xamarin forms WebView - webview

I have developed a simple Xamarin Forms App( targeting IOS and Android) with just a WebView and displaying an ASP.NET website in it.
It works as expected.
Now, my requirement is to store the authentication cookie when user logs in for the first time and attach that cookie every time the App gets opened so that the user does not need to login each time.
I have tried creating Custom WebView Render following the below code, but it doesn't seem to work for my scenario.
https://forums.xamarin.com/discussion/41039/setting-cookies-in-a-webview
I am able to access all cookies on WebView, but how do I store the necessary cookie and attach that cookie to WebView when the App gets opened again?
Any help would be appreciated.

android, in the onFinishLoad of the webview client:
CookieManager.Instance.Flush();
IOS:
in the onFinishLoad of the webview client to get yours cookies
(NSString)NSUserDefaults.StandardUserDefaults.ValueForKey((NSString)"CookiePZ8") ?? string.Empty
but you need to ad this line in your create of the OnElementChanged of your webview render
request["Cookie"] = (string)((NSString)NSUserDefaults.StandardUserDefaults.ValueForKey((NSString)"CookiePZ8") ?? string.Empty);
his.loadUrl(request);

Related

Launching an App from Custom URL from Safari not working as intended in iOS >12.3

We share the App deeplinks (Universal links) with our users over email, sometimes they get wrapped by email service providers for safety.
When user taps on these wrapped deeplinks, instead of opening the App directly it opens the url in Safari.
We have a page hosted on that url. We capture the deeplink there and try to open the App using Custom URL scheme (myurlscheme://). But if the App is not installed, we try to redirect the user to the App Store page.
It all worked okay until now, but seems like Apple made some changes in Safari in the new versions of iOS (>12.3).
What’s happening now is, if the App is installed and we open the App from Safari (from Custom URL), the App Store page opens in a split second after opening our App.
This is the Javascript code that we are using:
window.location.href = 'myurlscheme://';
setTimeout(function() {
window.location.href = "https://itunes.apple.com/us/app/myapp/id123456789?ls=1&mt=8";
}, 500);
Is anyone else experiencing this. If yes, were you able to find any solution?
Update:
If we set the timeout to 4000 (i.e. 4 seconds), then it does not redirect to the App Store after launching the App.

iOS: Open a registered open URL from within the same app

I am running into a situation which I am not sure is possible from technical/design point of view. Please advise.
Here is what I need:
I have an open URL registered for my native iOS app. I expect a request ID to be passed along with it and once hit I open that request.
From within my native iOS app, I need to open a web page in the webview. This page has few buttons in it.
A tap on the button in the webview should open the request inside my app. So, I want to trigger the registered open URL in step #1.
Web page data is dynamic and will change on the fly.
Is this a feasible design. Shall I consider something else.
Any advise/pointers will be appreciated.
This should be possible. Here's a though:
1: Implement the UIWebview delegate method shouldStartLoadWithRequest.
2: when you intercept that your webview is attempting to access the url yourapp://blah-blah-blah you can return NO instead dip into your appdelegate can manually call the function handleOpenURL.
I've seen something similar in the past with supporting oAuth (I believe it was with instagram) within one of our apps. We basically loaded up the login page in a UIWebview and then when we detected the the post login redirect we parsed the oAuth token from the url and called it good.
Good luck

Titanium Studio Webview not letting me interact with website

Part of an app I am working on needs to access an external website to answer a few questions.
When that is needed, I am opening a web view and the URL set to this site. The page loads fine, but there is no way to interact. The textfields cannot be edited and the buttons cannot be clicked. To make sure it was not my website (works from iOS safari fine) I pointed the web view to www.google.com and cannot click the search button there either. Basically:
var webView = Titanium.UI.createWebView({url: 'http://www.google.com'});
win.add(webView);
win.open();
Is there some trick to being able to interact with the website through a web view? At this time I cannot use a native app and web service and need to get the app working with the existing website to fill out this form.
Titanium Studio 2.1.2 and iOS6
Maybe are you putting some View (Ti.UI.View) after putting the WebView in the Window?

Titanium webview iframe doesnt seem to store cookies

I am developing an app using Appcelerators Titanium. The app consists of a webview. The webview shows i local page, iframe.html, and this iframe's src is pointed to a remote page.
However, this doesn't work out as i expected since it doesn't seem like the remote page can't store cookies when wrapped in an iframe. It works great on desktop and other devices. This seems to be an issue exclusive to iOS. I need the iframe, and i need cookies. What can i do to solve this?

iPad and iframe cookies

I am developing a Facebook canvas application using the iframe method, because of existing infrastructure the session data is set in a cookie between each page request (including jQuery JSON requests) this all works fine in Safari, Firefox, Chrome and IE( with the P3P header being set) but not in MobileSafari on the iPad (iOS 4.2).
I've been watching the debug as each page is loaded and it seems the session isn't being passed through as each page loads.
Does anyone know what it takes to get MobileSafari accepting cookies inside an iframe?
Thanks in advance!
Callum
One of my friends used this and said it worked
http://anantgarg.com/2010/02/18/cross-domain-cookies-in-safari/
EDIT: updated link

Resources