How to Detect in iOS Webapp When Switching Back to Safari from Background

How to detect focus when reopening Safari on iPhone?

try this:

if you trigger the link for the call set the actual time in a localStorage-item.

$("#yourButton").click(function() {

var actualTime = new Date().getTime();
window.localStorage.setItem('callStart', actualTime);

})

after that you need to read the Storage after user ends up the call.
You can set this in the document.ready on the opening page.

in $(document).ready(function() {})

// check for the localStorageItem
if (window.localStorage.getItem('callStart')) {

// get it
var timeStart = window.localStorage.getItem('callStart');

var now = new Date().getTime();

/*
Now calculate here the difference now - timeStart
and you will get seconds, minutes or whatever you want
*/

// !!! Dont forget to clear the localStorageItem
window.localStorage.removeItem('callStart');

}

This is what I would try. The Usage of the HTML5-localStorage gives you the possibility to store key/values and data isnt lost if user stops the app or device is automatically locked.

Hope this helps a bit.

ADDED: You even can store JSON as the value in the localStorageItem. So you can set an callID and implement a calling-history for your users.

Detect if iOS is using webapp

You have to detect this by using some javascript:

<script>
if (("standalone" in window.navigator) && // Check if "standalone" property exists
window.navigator.standalone){ // Test if using standalone navigator

// Web page is loaded via app mode (full-screen mode)
// (window.navigator.standalone is TRUE if user accesses website via App Mode)

} else {

// Web page is loaded via standard Safari mode
// (window.navigator.standalone is FALSE if user accesses website in standard safari)
}
</script>
</head>

Now the extra check "standalone" in window.navigator is needed because some browsers do not have the standalone property and you don't want your code to crash for those browsers.

iphone safari web app backgrounding

This is a standart behaviour.
as mentioned here: Prevent web app restart on iPad task switch You have to save the state into localStorage and check it on start up and fake the state.



Related Topics



Leave a reply



Submit