6

I have a web app.

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

I put this in there.

I add to home screen.

However, I realize that I always have to login again after I close the web app.

How do I make it keep the session?

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
TIMEX
  • 259,804
  • 351
  • 777
  • 1,080
  • Much googling has left me without an answer to this same question. I suspect you're meant to use local storage to re-login automatically or something, which is doable, but seems odd. – jhickner Apr 09 '12 at 04:55
  • I too have yet to find an easy solution for this. – YoungDinosaur Nov 07 '12 at 20:01

2 Answers2

1

There is an easy answer, but as of yet I was unable to find any reference to it in Apple's official documentation.

The trick is to do this:

// Start or resume session
session_start(); 

// Extend cookie life time by an amount of your liking
$cookieLifetime = 365 * 24 * 60 * 60; // A year in seconds
setcookie(session_name(),session_id(),time()+$cookieLifetime);

If you extend the lifetime of your session cookie like this, Safari will hold on to the session cookie and even allow sharing of the session between the 'home screen installed' version of your web app and normal visits through Safari itself.

For a more elaborate discussion, take a look at my answer to this question:

Maintain PHP Session in web app on iPhone

Community
  • 1
  • 1
Wilbo Baggins
  • 2,701
  • 3
  • 26
  • 39
  • This answer probably applies to a php-context, but as such provides no clue as to what the real issue in terms of iOS localstorage life-cycle (or the like) is – Frederik Struck-Schøning Jan 07 '19 at 11:25
  • The general solution is to extend the lifetime of the session cookie. The provided code in this answer is indeed PHP, but it should serve fine to illustrate the point. See the linked question for more background info. – Wilbo Baggins Jan 08 '19 at 18:46
-2

I use static class and static variable such as dictionary(string,object) to keep data when I have to access outside app. If you use FormAuthentication, you will notice

User.Identity.IsAuthenticated = true 

but session does not exist. you can use "User.Identity.Name" as key to get data in dictionary.

This works in ASP.Net MVC3

kleopatra
  • 51,061
  • 28
  • 99
  • 211