Location permission alert on iPhone with PhoneGap

2019-01-03 14:07发布

How do you change the string on the alert saying:

(Appname/whatever it is) would like to use your current location

Of course, I only want to change the appname part. Because when you use the PhoneGap framework, the string is very ugly, something like this:

/var/mobile/Applications/157EB70D-4AA7-826E-690F0CBE0F/appname.app/www/index.html

Someone having an idea?

19条回答
一纸荒年 Trace。
2楼-- · 2019-01-03 14:40

None of the above answers worked for me. My location request was already firing on deviceready. Adding the following to config.xml fixed the issue:

<gap:plugin name="org.apache.cordova.core.geolocation" />
查看更多
小情绪 Triste *
3楼-- · 2019-01-03 14:42

Although this question is much older, I found similar questions here and here.

For my resolution, I had to add NSLocationWhenInUseUsageDescription to the .plist file. However, I suppose since my geolocation plugin was out of date, I had to update it first. Then I had to remove/add the Cordova iOS platform. Finally, I added NSLocationWhenInUseUsageDescription to the .plist file.

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.

查看更多
唯我独甜
4楼-- · 2019-01-03 14:43
  • Just by including "cordova.js" file in your html file where you are accessing this location will resolve this issue. NOTHING FANCY REQUIRED.
查看更多
手持菜刀,她持情操
5楼-- · 2019-01-03 14:44

Since I was struggling for days now with the same problem and finally found the solution, I decided to share it with anyone who still was not able to fix it.

The solution is simple: The geolocation plugin was missing in the plugins directory within the www directory, even though I added the plugin via the phonegap command line interface AND the plugin files were in the /Plugins directory. So you only have to copy the missing files into /www/plugins and you are done. Just simple as that.

If anyone needs the missing files: http://d.pr/f/xqhq

btw: i am using cordova 3.2.0.

I hope this works for you as well!

查看更多
Rolldiameter
6楼-- · 2019-01-03 14:46

Finally fixed the issue.

IN the index.html just move your cordova.js up

<script src="cordova.js"></script>

as the first js file to be included (especially make sure it is above maps include js). This will make sure that the prompt shows only once.

No other codejs or ondeviceready is needed.

查看更多
等我变得足够好
7楼-- · 2019-01-03 14:47

I followed all the instructions and it still failed. In the end I played around with the PhoneGap demo and found the final solution:

  1. Move all the js files and html files into the same folder (not even sub-folder). Congratulations! Problem solved, no permission alert any more : )

  2. BTW, You'd better use a " setTimeout(function(){utility.getGeoData();},1000);" I found "document.addEventListener("deviceready", utility.getGeoData(), false);" not work for me.

Hope that helps when you find no solution above : )

Good luck!

查看更多
登录 后发表回答