14

I'm building a full-screen iPhone optimized web app. It gets launched from the homepage like a native app and behaves like a standalone app via the following directive, but it's just plain HTML/CSS/JavaScript, no PhoneGap involved.

<meta name="apple-mobile web-app-capable" content="yes" />

When trying to authenticate over OAuth, the redirect to Twitter (or any other OAuth provider) takes me out of my full-screen web app and into Mobile Safari. Once the Twitter auth completes, the redirect back to my app does not launch my homepage app, instead just redirects within Mobile Safari. Is it possible to do OAuth inside an iPhone homepage web app? Short of that, can I get the OAuth callback to re-launch my homepage web app?

ThinkingStiff
  • 62,391
  • 29
  • 139
  • 237
mustpax
  • 1,388
  • 11
  • 20
  • just wanted to say there is no way to programmatically re-launch an app (maybe you can on a jailbroken device but not under normal conditions) – mattacular Aug 15 '11 at 18:05
  • Just to clarify. Since you are building a web app, you are already in Mobile Safari. Do you mean to say that the authentication page opens in a new page in Safari? – Jon Nylander Aug 15 '11 at 19:36
  • 2
    When you save an iPhone optimized web app to the home page and run it from there it actually doesn't open in Safari. Well, it's still rendered by Safari under the covers, but it launches like a stand alone app. It gets it's own icon in the fast app switching task bar and everything. The problem is that a link to Twitter leaves that container. – mustpax Aug 15 '11 at 20:02

2 Answers2

15

I've had a similar problem recently, and found that if you set the URL in Javascript with a window.location.href="http://example.com/whatever" then iOS doesn't switch to Safari. I've managed to get PayPal checkout and Facebook login working in standalone web apps without switching to safari using this method! If you're submitting a form, do that via JS too and get the redirect URL from the response then set the location. As for handing back to your app afterwards, it depends on how the external service works.

If that's no good, you could do a pop-up alert('You will be passed to Safari for authentication. Reload this app afterwards.') before they get switched to Safari. Not great, but better than surprising them with automatically switching apps!

JoLoCo
  • 1,325
  • 1
  • 13
  • 19
  • Google OAuth still insists on switching to Safari from the "Select an account" screen if you request certain permission scope (e.g. https://www.googleapis.com/auth/youtube) and you have multiple accounts associated with your login. – Dunc Jan 05 '15 at 18:04
1

I´m assuming that you have a "manifest" meta tag to reference manifest.json file.

I suggest you to do the following workaround. It works perfect on ios safari web app:

https://stackoverflow.com/a/52286655/8390589

Jorge Valvert
  • 736
  • 7
  • 13