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条回答
forever°为你锁心
2楼-- · 2019-01-03 14:48

You need to do the geolocation after the device is ready. The following Jquery code, for example, will geolocate without that nasty alert:

$(function(){
  document.addEventListener("deviceready", onDeviceReady, false);
})

function onDeviceReady() {
  navigator.geolocation.getCurrentPosition(onSuccess, onError);     
}

function onSuccess(position) {
  // your callback here 
}

function onError(error) { 
  // your callback here
}
查看更多
beautiful°
3楼-- · 2019-01-03 14:48

I'm late to the party here, but will answer the question for reference. The answer is to use the geolocation functions found in phonegap.js which is included with Phonegap. You will be able to find such instructions on the Phonegap site at http://www.phonegap.com.

If you use navigator.geolocation, you are using the default Safari geolocation system. This happens as PhoneGap works by running your pages effectively in a Safari instance. If you include phonegap.js into your site, you can use a separate geolocation method exposed by PhoneGap's Objective-C code, which will present the behaviour seen in other apps where it asks for permission from [your app name].

查看更多
祖国的老花朵
4楼-- · 2019-01-03 14:50

I just followed the documentation and solved it. Open the terminal and cd to your project and enter following command. $ cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git

Also add this in your config.xml

<feature name="Geolocation">
    <param name="ios-package" value="CDVLocation" />
</feature>

It will solve this issue. :)

Source: http://docs.phonegap.com/en/3.0.0/cordova_geolocation_geolocation.md.html#The%20Command-line%0AInterface

查看更多
Explosion°爆炸
5楼-- · 2019-01-03 14:50

What is the Bundle display name of your project?

Try changing manually from the default value ${PRODUCT_NAME} and see..

That Permission to use location alert picks your bundle display name only!!

查看更多
beautiful°
6楼-- · 2019-01-03 14:52

To solve the issue I have to run cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git which adds (automatically) to the config.xml the following:

<feature name="Geolocation">
     <param name="ios-package" value="CDVLocation" />
</feature>

To get things working I have to put also this lines into the config.xml:

<plugins>
        <plugin name="Device" value="CDVDevice" />
        <plugin name="Logger" value="CDVLogger" />
        <plugin name="Compass" value="CDVLocation" />
        <plugin name="NetworkStatus" value="CDVConnection" />
        <plugin name="Debug Console" value="CDVDebugConsole" />
        <plugin name="Geolocation" value="CDVLocation" />
        <plugin name="SplashScreen" value="CDVSplashScreen" />
        <plugin name="Battery" value="CDVBattery" />
        <plugin name="Globalization" value="CDVGlobalization" />
    </plugins>

Hope it could be helpful.

查看更多
我想做一个坏孩纸
7楼-- · 2019-01-03 14:54

After making sure my geolocation request was called after the device was ready, making sure the geolocation plugin is correctly installed and configured, I was still receiving the unsightly popup.

I resolved it by moving and referencing my cordova.js file and cordova_plugins.js files into the root directory of my application (they were originally in a subfolder), so the path to cordova.js would be:

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

I feel this should be included in the documentation (maybe it is, but I haven't managed to find it)

查看更多
登录 后发表回答