菜鸟教程小白 发表于 2022-12-12 13:17:57

ios - 动态添加参数到起始 URL


                                            <p><p>在使用Cordova之前,我曾经添加了一个动态参数,检测手机OS语言并放在URL中,这样我就可以用用户的语言查看网站页面了。</p>

<pre><code>NSString * language = [ objectAtIndex:0];
NSString *urlString = ;
</code></pre>

<p>但是使用 Cordova 会强制我加载静态 URL,有什么办法可以在应用启动时将语言参数插入到 URL 中吗?</p>

<p>谢谢。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您可以创建 <a href="http://cordova.apache.org/docs/en/latest/guide/hybrid/plugins/index.html" rel="noreferrer noopener nofollow">plugin</a>使用您已经在使用的代码检测手机语言,并在成功回调中使用 javascript 重定向到您的网站,如下所示:</p>

<p><code>window.location.href = 'http://mywebsite.com/?language='+pluginResult;</code></p>

<p>您也可以在 <code>didFinishLaunchingWithOptions</code> 方法中的 <code>AppDelegate.m</code> 中添加它,就在 return 之前</p>

<p><code>NSString * 语言 = [ objectAtIndex:0];
self.viewController.startPage = ;</code></p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 动态添加参数到起始 URL,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/43236760/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/43236760/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 动态添加参数到起始 URL