iOS 6 breaks GeoLocation in webapps (apple-mobile-

2019-01-16 07:23发布

I have an app that does a simple textbook navigator.geoLocation.watchPosition(...) that works great in iOS 5.x both in Safari and as a web app (using apple-mobile-web-app-capable meta tag).

However, in iOS6, GeoLocation does not work in the webapp. It still works in safari as expected, but when I run the webapp, it prompts me for location permission, then silently fails. I see the location icon, but no events are thrown from watchLocation. I get no error events or any location events.

Has anyone run into this? Any workarounds? It's definitely iOS6 specific and also specific to the apple-mobile-web-app-capable/webapp.

11条回答
狗以群分
2楼-- · 2019-01-16 08:13

It appears it only works once, then any secondary calls fail. One alternative is to cache the result and use the cached result if you have one, though this means you can't have an app that follows someone's position.

查看更多
姐就是有狂的资本
3楼-- · 2019-01-16 08:13

This is not exactly an answer as it seems like Home Screen apps in ios6 has some bug related to GeoLocation, but I found the following link very helpful. It explains that as Home Screen apps are now stored like native apps, they have their own storage/caching.

Geolocation works on the first iteration but fails to update from then on. the work around is to remove the following meta tag so that Home Screens app run in Browser mode (I am not sure if it is exactly call a Browser mode). The app will unfortunately render with the browser headers and footers, but GeoLocationwill be working again.

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

iOS 6 Geolocation and Local Data Storage

"Data in Home Screen apps are now stored like native apps. Native apps each have their own sandbox where their data is stored, backed up and restored to. Prior to iOS 6, Home Screen apps shared data with the same app running in the browser. If the user cleared the cache in the browser, the Home Screen version of the app would lose its data too.With iOS 6, Home Screen apps’ data gets saved to a sandbox just like native apps. Backups and restores handle the data properly, and clear cache in the browser will not affect them."

查看更多
叼着烟拽天下
4楼-- · 2019-01-16 08:14

This is definitely a bug but I found a work around. You aren't going to like this but at least it will get your web app working again. You need to examine the User Agent header and if it contains "iPhone OS 6" then do not use:

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

Yes, this means that it won't be a true web app and you will get the Safari header and footer bars. But at least it will make your app work again from the home screen. You can see how this works by going to my site www.nextbus.com.

Note that it appears that Google ran into this problem. Try going to maps.google.com and then adding the web app to your homescreen. The geolocation will work for it but you will indeed see the ugly Safari header and footer bars.

Please complain loudly to Apple!

查看更多
做个烂人
5楼-- · 2019-01-16 08:16

You must take care of non secure content loaded. For me loading all javascript, images and css from secure context solved the problem with safari.

查看更多
家丑人穷心不美
6楼-- · 2019-01-16 08:21

I can confirm I get the same problem when running my web app in fullscreen.

Interestingly, when Safari in Fullscreen asked permission to use my location, the website title was 'web' rather than the title of the website, as in previous versions of iOS.

Removing the "apple-mobile-web-app-capable" meta tag is fine, and it works, but only if you "Add to Homescreen" again. We have ~7000 daily users who have already added our icon to their homescreen. Getting them to do so again, then potentially again when a fix is implimented isn't great.

查看更多
登录 后发表回答