Forum Xamarin.Forms

Closing browser without user interaction

I have a scenario where I need to open a browser to remove user cookies for logging out. So the process is:

  1. Open browser (Chrome CustomTab or SFSafariView depending on OS) and point it towards my URL to delete cookies.
  2. Send the user back to the mobile app login screen.

Where I'm having an issue is step 2. How do I go about closing/minimizing the browser without requiring user interaction? The only thing I have found so far is to run System.Diagnostics.Process.GetCurrentProcess().Kill(); which closes the entire app, but I have seen comments online that doing this might cause the app to get rejected by Google and/or Apple.

Any ideas on how I can solve this?

Answers

  • GraverobberGraverobber Member ✭✭✭
    edited January 8

    @ryanbuening said:
    The only thing I have found so far is to run System.Diagnostics.Process.GetCurrentProcess().Kill(); which closes the
    entire app, but I have seen comments online that doing this might cause the app to get rejected by Google and/or
    Apple.

    Any ideas on how I can solve this?

    My answer is more a Brainstorming :D but who knows maybe it helps.

    First off all do I understand your Scenario correctly?
    You open a third party app (= Browser) on the device in order to delete the cookie
    You want to go back to your app once the deletion completed.

    The problem is that you don't have much control about what happens outside your app and inside the browser.
    You also can't really know if the site to delete the cookie finished loading yet or not.

    So here are some ideas:

    Register an URLScheme in your app itself and once the cookie deletion finished, call the Urlscheme from your website in order to bring your app back to front. I think this is the easiest and most straight forward solution and should actually work.
    The only thing that might happen is that there will be a popup appearing asking the user if he allows to trigger the scheme.

    Other ideas:
    Open your Browser as before but before the line where you trigger the UrlScheme call, start a background service of your app.
    In this service wait for an amount of time, like 20 to 30 seconds.
    When the time expires bring your own app to front instead of closing the Browser.
    (If you don't want the browser to stay on your site, perhaps there is a Javascript call or whatever that allows to close the tab/page. (I'm no expert on Web :D) so what I mean is once your cookie deletion script finished call the script to close the page.)
    How to bring you app to the front is another issue, as you don't really have control about that as well.
    Perhaps you can give your app an URL Scheme which you trigger yourself once the timer ended. It should bring your app to front.

    Another idea would be to set an alarm in the device which will fire within the next 20 to 30 seconds. Once it fires bring your app to front.

    One more idea would be to forget about the service or timer and use push notifications. Once the cookie deletion finished execute a push notification to your app. When receiving the notification bring the app to front.
    This solution would also allow less interruption. You could show a notification saying something like "Cookie deletion finished, want to return to " and then the user taps the banner to return to the app.

    Thats all for now :D

  • ryanbueningryanbuening Member ✭✭

    @Graverobber thanks for the detailed reply. I mixed together a solution where I am opening an in-app browser to remove the cookie and then navigating back to the login screen.

Sign In or Register to comment.