简体   繁体   中英

Mapbox location request prompt in ios ionic app

I have a React app that I'm turning into a phone app with Ionic and capcitorjs. A mapbox map is a big part of the app and when you open the app, it requests permission to access the phone's location with a pretty normal prompt. This is fine, and the map centers on the user properly (using @capacitor/geolocation) when the app is opened. But when the user pushes the mapboxgl.GeolocateControl button that centers on the user and adds the blue location dot, the prompt is strange and I don't see where to change it. The prompt to use the user's location (despite already having permission) is:

"://" Would Like To Use Your Current Location

Don't Allow | Ok

Where can I change this prompt? It does not appear on Android so this is only an iOS problem. For the first prompt to request geolocation access, that is editable in the Info.plist file in XCode, but this "Would Like..." prompt doesn't even appear in the Info.plist. It seems to be caused by mapbox. Can the prompt be changed with @capacitor/geolocation?

Here are the relevant dependencies for this npm app:

"ionic": "^5.4.16",
"mapbox-gl": "^2.5.1",
"@capacitor/core": "^3.2.4",
"@capacitor/geolocation": "^1.1.0",
"@mapbox/mapbox-sdk": "^0.13.2",
"react": "^17.0.2",
"@capacitor/android": "^3.2.4",
"@capacitor/app": "^1.0.3",
"@capacitor/cli": "^3.2.4",
"@capacitor/ios": "^3.2.4",

ios has two type of geo location permissions

  1. one time use location permission (next time it will again ask for permission)
  2. when app use (it requires when app is running mode) the third permission is always which not allowed in ios 12

Solution :

in xcode info.plist add these two properties

NSLocationAlwaysUsageDescription

NSLocationWhenInUseUsageDescription 

and some text in there string value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM