简体   繁体   English

iOS上的位置提醒

[英]Location alert on ios

I have a problem with my app on iOS created using ionic. 我在使用ionic创建的iOS上的应用存在问题。 In my home menu, when I press a button, my app tries to get my location and it shows me two alerts: one in Italian(that's right) and one in english: 在我的主菜单中,当我按下一个按钮时,我的应用尝试获取我的位置,并且向我显示了两个警报:一个是意大利语(正确),另一个是英语:

ITA: ITA:

意大利警报

ENGLISH: 英语:

英文警报

The second alert is so ugly. 第二个警报是如此丑陋。 I would like that the alert will be: "MYAPP vuole usare la tua posizione". 我希望警报为:“ MYAPP vuole usare la tua posizione”。 How can I change the text of the second alert? 如何更改第二个警报的文本?

You will probably need to wrap your Cordova location request inside an ionicPlatform.ready in your controller 您可能需要将Cordova位置请求ionicPlatform.ready在控制器中的ionicPlatform.ready

.controller("MapController", ["$scope", "$cordovaGeolocation", "$ionicPlatform", function($scope, $cordovaGeolocation, $ionicPlatform) {

      $ionicPlatform.ready( function() {

            $cordovaGeolocation
              .getCurrentPosition()
              .then(function (position) {
                // do something
                }
              }, function(err) {
                // error
              });

      })

}])

You need to know there are difference between Javascript alert and native alerts. 您需要知道Javascript警报和本机警报之间存在区别。

You could probably use cordova notification plugin and show the desire output inside it. 您可能可以使用cordova notification插件并在其中显示期望的输出。

You could get plugin information from here: https://cordova.apache.org/docs/en/3.0.0/cordova_notification_notification.md.html 您可以从此处获取插件信息: https : //cordova.apache.org/docs/en/3.0.0/cordova_notification_notification.md.html

and download the plugin from github repo 并从github repo下载插件

Code implementation would be like: 代码实现如下:

$cordovaGeolocation
              .getCurrentPosition()
              .then(function (position) {
                //here call the notify method
                navigator.notification.alert(message, alertCallback, [title], [buttonName]) // instead of message pass the position 
                //title it so index.html will not be displaying
                }
              }, function(err) {
                // error
              });

If you're worried about the looks you could try using a custom alert like sweet alert. 如果您担心外观,可以尝试使用自定义提醒(如甜蜜提醒)。 http://t4t5.github.io/sweetalert/ http://t4t5.github.io/sweetalert/

JS: JS:

var script_0 = document.createElement('script');
script_0.src = "https://cdn.rawgit.com/t4t5/sweetalert/master/dist/sweetalert.min.js";
document.body.appendChild( script_0 );


var link_0 = document.createElement('link');
link_0.rel = "stylesheet";
link_0.type = "text/css";
link_0.href = "https://cdn.rawgit.com/t4t5/sweetalert/master/dist/sweetalert.css";
document.body.appendChild( link_0 );

or HTML: 或HTML:

<script src="https://cdn.rawgit.com/t4t5/sweetalert/master/dist/sweetalert.min.js">     </script>
<link rel="stylesheet" type="text/css" href="https://cdn.rawgit.com/t4t5/sweetalert/master/dist/sweetalert.css">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM