Page 1 of 1

iPhone 5s and online/offline event

Posted: Sat Dec 21, 2013 8:45 pm
by Adam Garbinski

Hello,
I have the following issue regarding iOS 7.0.4 and iPhone 5s:
When I try to simulate 'online' and 'offline' event by switching the phone to 'Flight mode' it triggers at leas two consecutive events instead just one. So first I got 'offline' event detected and then after 1 second I get 'online' event detected, even if there is a clear evidence that the phone is in 'Flight mode' (airplane icon, and all communication ports shut down). The same issue occurs when I turn off 'Flight mode', so I get at least two events detected instead one.
From my tests it appears that the sequence is as follows:

Turn on 'Flight mode' (phone offline)
1) offline event triggered
2) online event triggered

Turn off 'Flight mode' (phone online):
1) offline event triggered
2) online event triggered
3) offline event triggered

This issue is not present on iPhone 4s.
Do you know a simple solution to remedy this problem? I have local storage variable dependent on that events so app logic is broken down by this issue.


iPhone 5s and online/offline event

Posted: Sat Dec 21, 2013 10:46 pm
by Adam Garbinski

Well, I was able to fix it on my own by adding this JS to 'onLine' event in Appery builder:

var currenttime = new Date();
var lasteventtime = new Date(parseInt(localStorage.getItem('onLineTime')));
var timespan = (currenttime.getTime() - lasteventtime);
if (timespan = 5000 || isNaN(timespan)){
if (localStorage.OnLine == 'false'){
localStorage.setItem('OnLine', 'true');
localStorage.setItem('onLineTime', currenttime.getTime());
}
}

and this JS to 'offLine' event:

var currenttime = new Date();
var lasteventtime = new Date(parseInt(localStorage.getItem('onLineTime')));
var timespan = (currenttime.getTime() - lasteventtime);
if (timespan = 5000 || isNaN(timespan)){
if (localStorage.OnLine == 'false'){
localStorage.setItem('OnLine', 'true');
localStorage.setItem('onLineTime', currenttime.getTime());
}
}

I wonder if there is any other solution.


iPhone 5s and online/offline event

Posted: Sat Dec 21, 2013 10:58 pm
by Illya Stepanov

Hi Adam,

Thank you for the update.

We'll look if there is an another solution, but need to test it on the iPhone 5S, so it might take some time.


iPhone 5s and online/offline event

Posted: Mon Dec 23, 2013 5:21 pm
by Maryna Brodina

Hello! It's not reproducible on iPhone 5/ iOS7. Unfortunately we don't have opportunity to test on iPhone 5s.