Fix Cordova Geolocation Ask for Location Message

后端 未结 2 899
梦毁少年i
梦毁少年i 2020-12-03 19:11

Does anyone have experience using cordova, html and know how to fix this geolocation message issue for iOS? I just want the message to say the app name followed by the line,

相关标签:
2条回答
  • 2020-12-03 19:49

    In addition to the answer from DaveAlden, I had to remove the old version of the geolocation plugin and add the new one. Then I had to remove/add the Cordova iOS platform. Only then could I add NSLocationWhenInUseUsageDescription to the .plist file with success.

    First, remove/add the geolocation plugin:

    cordova plugin rm org.apache.cordova.geolocation
    cordova plugin add org.apache.cordova.geolocation
    

    Second, remove/add the iOS platform:

    cordova platform rm ios
    cordova platform add ios
    

    Last, add NSLocationWhenInUseUsageDescription to the .plist. Open /platforms/ios/{project}/{project}-Info.plist and add the following:

    <key>NSLocationWhenInUseUsageDescription</key>
    <string>[App Name] would like to access your location when running and displayed.</string>
    

    See this iOS Developer Library link for detailed information regarding NSLocationWhenInUseUsageDescription versus NSLocationAlwaysUsageDescription versus NSLocationUsageDescription.

    Location permission alert on iPhone with Cordova is a possible duplicate.

    0 讨论(0)
  • 2020-12-03 20:07

    To customise the iOS location permission request message, you need to add a property to your project's .plist.

    If your app requests permission to use location in the background, you want the following key (set the string value to anything you like):

    <key>NSLocationAlwaysUsageDescription</key>
    <string>My app requires constant access to your location, even when the screen is off.</string>
    

    If your app only uses location while in the foreground, then add the following key:

    <key>NSLocationWhenInUseUsageDescription</key>
    <string>My app requires access to your location when the screen is on and the app is displayed.</string>
    
    0 讨论(0)
提交回复
热议问题