ios - 使用 Ionic 包装 Angular2 应用程序 - 地理定位问题

标签 ios angular ionic-framework geolocation ionic2

我有一个现有的响应式 Angular 2 应用程序,我想使用 Ionic 对其进行包装并部署到应用程序商店。该应用程序将在两种网络浏览器上运行,并作为 iOS 和 Android 上的 native 应用程序运行。

我现在已经基本解决了这个问题,但有一个问题。我需要在我的第一个屏幕上使用 geolocation,我的网络应用程序使用 navigator.geolocation.getCurrentPosition 执行此操作,正如您所期望的那样。这在 web 中非常有效,请求用户许可,然后执行 geolocation

在 iOS 版本中,在 cordova-plugin-geolocation 中标记后,我可以弹出一条消息以允许地理定位,但此消息使用长路径

("/var/containers/bundle/application/{{GUID}}/{{APPNAME}}/www/index.html" would like to use your current location).

这看起来很老套和业余,老实说,我可能会删除任何给我这样的消息的应用程序。我想弄清楚如何让这条消息只说出我的应用程序的名称。以下是我尝试过的一些方法...

  • Adding NSLocationWhenInUseUsageDescription and it's variations to my plist file. This results in me getting a message with the app name first, and then getting a second message with the path.
  • Importing 'ionic-native' in my angular 2 app and trying to use Geolocation as a wrapper -- no change
  • Waiting for the "deviceready" event to do geolocation -- no change
  • Setting a long delay (up to 30 seconds) with setTimeout before doing geolocation -- no change

我讨厌这样的想法,即我必须有两个代码库才能通过应用商店分发 channel 部署一个简单的网络应用程序。当然有一些解决方法,我只是还没有想到。有什么建议吗?

最佳答案

所以,这实际上有点简单。构建的 index.html 文件只需要具有 ionic javascript 引用,如下所示:

<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="cordova.js"></script>

我修改了我的 gulp 文件,该文件由 ionic 的 webpack build 处理,以便在结束 head 标记之前将它们放入,现在我对地理定位的调用可以使用正确的消息传递。

navigator.geolocation.getCurrentPosition((pos) => { 
   //do things with pos
});

关于ios - 使用 Ionic 包装 Angular2 应用程序 - 地理定位问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40166724/

相关文章:

ios - 调整 CVPixelBuffer 的大小

ios - 使用 swift 3 在后台打开 url?

javascript - 在 Angular 中共享来自 JS 和 LESS 的变量

html - <select> 标签在 ionic 中的某些 android 设备上不起作用

javascript - Stripe 结帐 css 内容策略错误

javascript - Angular 自定义焦点指令不适用于 ion-item(但适用于 native &lt;input/>)

ios - Firebase Analytics 日志错误 Swift 3

ios - UIScrollView、自动布局和 subview

html - 如何过滤下拉列表以在列表顶部显示某些值?

angular - 使用 Jasmine Karma 测试一个分支