Cordova iOS location message

后端 未结 5 1803
忘了有多久
忘了有多久 2020-12-19 01:37

I use the plugin cordova-plugin-geolocation. My only issue is that the message prompt to allow location looks like this:

/var/container/bundle/applica

相关标签:
5条回答
  • 2020-12-19 02:14

    It seems like the version 3.0.0 of cordova-plugin-geolocation ignores the install parameter

    --variable GEOLOCATION_USAGE_DESCRIPTION=""

    like Bruno Peres said above.

    It works fine for me installing the 2.4.3 version.

    0 讨论(0)
  • 2020-12-19 02:19

    From docs:

    iOS Quirks

    Since iOS 10 it's mandatory to add a NSLocationWhenInUseUsageDescription entry in the info.plist.

    NSLocationWhenInUseUsageDescription describes the reason that the app accesses the user's location. When the system prompts the user to allow access, this string is displayed as part of the dialog box. To add this entry you can pass the variable GEOLOCATION_USAGE_DESCRIPTION on plugin install.

    Example: cordova plugin add cordova-plugin-geolocation --variable GEOLOCATION_USAGE_DESCRIPTION="your usage message"

    If you don't pass the variable, the plugin will add an empty string as value.

    To solve your problem, try:

    Uninstall the plugin:

    cordova plugin remove cordova-plugin-geolocation
    

    Reinstall with:

    cordova plugin add cordova-plugin-geolocation --variable GEOLOCATION_USAGE_DESCRIPTION="my_project would like to use your location"
    
    0 讨论(0)
  • 2020-12-19 02:24

    The solution has changed for cordova-plugin-geolocation: "4.0.0". This is what you need to add in your config.xml:

    <edit-config target="NSLocationWhenInUseUsageDescription" file="*-Info.plist" mode="merge">
        <string>need location access to find things nearby</string>
    </edit-config>
    

    For more information: https://github.com/apache/cordova-plugin-geolocation

    0 讨论(0)
  • 2020-12-19 02:25

    If you are targetting iOS 8 and later (I my opinion, no need to target older versions anymore...), there are two keys available for configuration:

    NSLocationAlwaysUsageDescription

    This key lets you describe the reason your app accesses the user’s location information at all times. Include this key when your app uses location services in a potentially nonobvious way while running in the foreground or the background. For example, a social app might include this key when it uses location information to track the user’s location and display other users that are nearby. In this case, the fact that the app is tracking the user’s location might not be readily apparent. The system includes the value of this key in the alert panel displayed to the user when requesting permission to use location services.

    NSLocationWhenInUseUsageDescription

    This key lets you describe the reason your app accesses the user’s location information while your app runs in the foreground and otherwise when in use. Include this key when your app uses location services to track the user’s current location directly. This key does not support using location services to monitor regions or monitor the user’s location using the significant location change service. The system includes the value of this key in the alert panel displayed to the user when requesting permission to use location services.

    So in your iOS project info.plist file you can add the following:

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

    Access location only when app is used

    <key>NSLocationWhenInUseUsageDescription</key>
    <string>my_project requires access to your location only when being used.</string>
    
    0 讨论(0)
  • 2020-12-19 02:30

    There are 3 possible reasons for displaying the path to the index.html instead of the name of your app:

    1. You have not installed the plugin (or it's not installed correctly)
    2. You are not waiting for the device ready event to call the plugin
    3. You have not linked the cordova.js file in the index.html

    As you say that you have installed the plugin and you are using it on device ready event, then it must be that you have forgotten to link the cordova.js in the index.html or the plugin wasn't installed correctly. Check that you have the cordova.js linked and if you have it, remove the plugin and add it again, removing and re adding the iOS platform might help too

    0 讨论(0)
提交回复
热议问题