菜鸟教程小白 发表于 2022-12-11 17:54:06

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


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

<p>我现在已经基本解决了这个问题,但有一个问题。我需要在我的第一个屏幕上使用 <code>geolocation</code>,而我的 Web 应用程序使用 <code>navigator.geolocation.getCurrentPosition</code> 如您所愿。这在网络中非常有效,请求用户许可,然后执行 <code>geolocation</code>。</p>

<p>在 iOS 版本中,我在 <code>cordova-plugin-geolocation</code> 中添加标签后,我可以弹出一条消息以允许地理定位,但此消息使用长路径</p >

<blockquote>
<p>(&#34;/var/containers/bundle/application/{{GUID}}/{{APPNAME}}/www/index.html&#34;
would like to use your current location).</p>
</blockquote>

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

<blockquote>
<ul>
<li>Adding <code>NSLocationWhenInUseUsageDescription</code> and it&#39;s variations to my <code>plist</code> file. This results in me getting a message with the app
name first, and then getting a second message with the path.</li>
<li>Importing &#39;ionic-native&#39; in my angular 2 app and trying to use Geolocation as a wrapper -- no change</li>
<li>Waiting for the &#34;deviceready&#34; event to do geolocation -- no change</li>
<li>Setting a long delay (up to 30 seconds) with setTimeout before doing geolocation -- no change</li>
</ul>
</blockquote>

<p>我讨厌我必须拥有两个代码库才能通过应用商店分发 channel 部署一个简单的网络应用程序的想法。当然,有一些我还没有想到的解决方法。有什么建议吗?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>所以,事实证明这有点简单。构建的 index.html 文件只需要具有 ionic javascript 引用,如下所示:</p>

<pre><code>&lt;script src=&#34;lib/ionic/js/ionic.bundle.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;cordova.js&#34;&gt;&lt;/script&gt;
</code></pre>

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

<pre><code>navigator.geolocation.getCurrentPosition((pos) =&gt; {
   //do things with pos
});
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 使用 Ionic 包装 Angular2 应用程序 - 地理定位问题,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/40166724/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/40166724/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 使用 Ionic 包装 Angular2 应用程序 - 地理定位问题