iphoneweb-applicationsiphone-web-app

iPhone Web App - Session & Current url lost when call answered


I have a multi-page website that is designed to work as a web-app on an iPhone.

It has the usual:

<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<link rel="apple-touch-startup-image" href="/images/startup.png" /> 

The site doesn't use Sencha or Javascript to navigate between pages, just standard anchor links, and page-reloads (I'm aware that the standard approach to web-apps is to use a Sencha-like interface).

It works perfectly fine when launched from the iPhone homescreen, and works the same as when viewed through Safari.

An issue seems to arise, though, when a phone call is answered mid-session.

Once the call is complete, the iPhone (version 4 in this case) reverts back to the web-app, but instead of restoring the previously-viewed page it reloads the homescreen (the same page that is loaded when the web-app is initiated)

When viewing the site in Safari, and accepting a call, it doesn't do this and maintains the url and current session values.

Is this a known issue in web-apps? Is there a workaround?

(one idea I have is to maintain the session and url values in a local SQLite database, but I'm not sure if this is the best approach)


Solution

  • 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);
    

    I tested this to work on iOS 4.2.1, 5.1.1, 6.0 and 6.1. The session is even restored after turning off and restarting the device.

    For a more elaborate discussion of this strategy you can take a look at my answer of this question: Maintain PHP Session in web app on iPhone