iOS Use Current Location Permission dialog is shown twice in Phonegap app

不想你离开。 提交于 2019-12-01 17:31:16

问题


I have a Phonegap app. I am including cordova.js in the HTML (but not in the www directory), I am waiting for deviceready to be fired, and then I'm calling

navigator.geolocation.getCurrentPosition(successCallback,failCallback);

I'm receiving both versions of the dialog (in this order):

Native Dialog - http://i.stack.imgur.com/H5y1O.png
HTML Dialog - http://i.stack.imgur.com/XbcmR.png


回答1:


If you're using version 3+ of PhoneGap, make sure you're correctly including the plugin.

From the PhoneGap v3.0.0 API Docs :

As of version 3.0, Cordova implements device-level APIs as plugins. Use the CLI's plugin command, described in The Command-line Interface, to add or remove this feature for a project




回答2:


I had the same problem, that's because there was not successfully installed phonegap geolocation plugin. Do you know how install it? Please check how to on http://docs.phonegap.com/en/3.0.0/guide_cli_index.md.html#The%20Command-line%20Interface




回答3:


Do not call getCurrentPosition immediately after deviceready has been fired. geolocation plugin is not ready, so navigator.geolocation.getCurrentPosition actually calls HTML5 api, then you see the HTML dialog. I do below to make sure geolocation plugin is ready before calling navigator.geolocation.getCurrentPosition in my ionic project.

    var my_getposition = function() {
        if (ionic.Platform.isIOS() && !window.Coordinates) {
            $timeout(function(){ my_getposition(); }, 500);
            return;
        }
        navigator.geolocation.getCurrentPosition(...);
    }



回答4:


You have to run "cordova prepare" in order to change the config.xml and it will automatically generate cordova_plugins.js that will be used for the geolocation plugin.

Just beware because when you do run cordova prepare it will erase all your /www folder.

Tipically you would have to add all the plugins and set up your environment before you add your code to the /www folder...



来源:https://stackoverflow.com/questions/19009776/ios-use-current-location-permission-dialog-is-shown-twice-in-phonegap-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!