iPhone/Safari: How can I continue to execute javas

2020-03-02 04:10发布

问题:

Many posts address this for iPhone apps, but I need to know how to do this for javascript on a web page.

My specific problem is that I want to track the device's location over a long period of time (say a car trip). This becomes a problem when the device sleeps (and maybe during a phone call, I haven't tried that case yet).

I'm open to any ideas, including preventing sleep mode (but since I'm in Safari, I'm not sure how much control I'd have to do that).

回答1:

You can't. Web pages do not execute javascript unless (1) the page is frontmost and (2) Safari is actually active. Safari does not remain active when the device is asleep.

If you think about it, this functionality would be a massive privacy breach. Imagine how you'd feel if you visited a web page that then secretly tracked your location even when your device was off! You'd be very angry. Even if you could do this technologically, people may be upset if they found out you did it.

Location info is closely guarded for reasons of privacy and physical safety (think about stalkers and your web page.) That is why you get a dialog asking to use the Location Manager the first time you get a location.