久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<i id='XFoKU'><tr id='XFoKU'><dt id='XFoKU'><q id='XFoKU'><span id='XFoKU'><b id='XFoKU'><form id='XFoKU'><ins id='XFoKU'></ins><ul id='XFoKU'></ul><sub id='XFoKU'></sub></form><legend id='XFoKU'></legend><bdo id='XFoKU'><pre id='XFoKU'><center id='XFoKU'></center></pre></bdo></b><th id='XFoKU'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='XFoKU'><tfoot id='XFoKU'></tfoot><dl id='XFoKU'><fieldset id='XFoKU'></fieldset></dl></div>

<legend id='XFoKU'><style id='XFoKU'><dir id='XFoKU'><q id='XFoKU'></q></dir></style></legend>
  • <small id='XFoKU'></small><noframes id='XFoKU'>

    <tfoot id='XFoKU'></tfoot>
    • <bdo id='XFoKU'></bdo><ul id='XFoKU'></ul>

        如何防止 WKWebView 重復(fù)請(qǐng)求訪問(wèn)位置的權(quán)限?

        How to prevent WKWebView to repeatedly ask for permission to access location?(如何防止 WKWebView 重復(fù)請(qǐng)求訪問(wèn)位置的權(quán)限?)
        <tfoot id='uX9yq'></tfoot>

        <i id='uX9yq'><tr id='uX9yq'><dt id='uX9yq'><q id='uX9yq'><span id='uX9yq'><b id='uX9yq'><form id='uX9yq'><ins id='uX9yq'></ins><ul id='uX9yq'></ul><sub id='uX9yq'></sub></form><legend id='uX9yq'></legend><bdo id='uX9yq'><pre id='uX9yq'><center id='uX9yq'></center></pre></bdo></b><th id='uX9yq'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='uX9yq'><tfoot id='uX9yq'></tfoot><dl id='uX9yq'><fieldset id='uX9yq'></fieldset></dl></div>
          <tbody id='uX9yq'></tbody>

          • <small id='uX9yq'></small><noframes id='uX9yq'>

                <bdo id='uX9yq'></bdo><ul id='uX9yq'></ul>

                  <legend id='uX9yq'><style id='uX9yq'><dir id='uX9yq'><q id='uX9yq'></q></dir></style></legend>
                  本文介紹了如何防止 WKWebView 重復(fù)請(qǐng)求訪問(wèn)位置的權(quán)限?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  我的應(yīng)用中有一個(gè) WKWebView,當(dāng)我開(kāi)始瀏覽 www.google.com 或任何其他需要定位服務(wù)的網(wǎng)站時(shí),會(huì)出現(xiàn)一個(gè)彈出窗口,詢問(wèn)是否允許訪問(wèn)該位置即使我已經(jīng)同意分享我的位置,也可以使用設(shè)備.

                  I have a WKWebView in my app and when I start browsing www.google.com or any other website that requires location service, a pop up window appears, asking for the permission to access the location of the device even if I have already accepted to share my location.

                  我為管理此位置信息所做的唯一一件事就是在我的 info.plist 中添加了 NSLocationWhenInUseUsageDescription 屬性.

                  The only thing I did to manage this location stuff is that I added the NSLocationWhenInUseUsageDescription attribute in my info.plist.

                  我在網(wǎng)上找不到任何答案,所以任何想法都將不勝感激.

                  I couldn't find any answers on the web so any idea would be really appreciated.

                  推薦答案

                  事實(shí)證明這很困難,但可以做到.您必須注入 JavaScript 代碼來(lái)攔截對(duì) navigator.geolocation 的請(qǐng)求并將它們傳輸?shù)侥膽?yīng)用程序,然后使用 CLLocationManager 獲取位置,然后將位置注入回 JavaScript.

                  Turns out it's quite hard, but possible to do. You have to inject JavaScript code which intercepts requests to navigator.geolocation and transfer them to your app, then get the location with CLLocationManager, then inject location back to the JavaScript.

                  以下是簡(jiǎn)要方案:

                  1. WKUserScript 添加到您的 WKWebView 配置中,它會(huì)覆蓋 navigator.geolocation 的方法.注入的 JavaScript 應(yīng)該如下所示:

                  1. Add WKUserScript to your WKWebView configuration which overrides methods of navigator.geolocation. Injected JavaScript should look like this:

                  navigator.geolocation.getCurrentPosition = function(success, error, options) { ... };
                  navigator.geolocation.watchPosition = function(success, error, options) { ... };
                  navigator.geolocation.clearWatch = function(id) { ... };
                  

                • 使用 WKUserContentController.add(_:name:) 將腳本消息處理程序添加到您的 WKWebView.注入的 JavaScript 應(yīng)該調(diào)用您的處理程序,如下所示:

                • With WKUserContentController.add(_:name:) add script message handler to your WKWebView. Injected JavaScript should call your handler, like this:

                  window.webkit.messageHandlers.locationHandler.postMessage('getCurrentPosition');
                  

                • 當(dāng)網(wǎng)頁(yè)請(qǐng)求位置時(shí),此方法將觸發(fā) userContentController(_:didReceive:),以便您的應(yīng)用知道網(wǎng)頁(yè)正在請(qǐng)求位置.像往常一樣在 CLLocationManager 的幫助下找到您的位置.

                • When a web page will request a location, this method will fire userContentController(_:didReceive:) so your app would know web page is requesting location. Find your location with the help of CLLocationManager as usual.

                  現(xiàn)在是時(shí)候使用 webView.evaluateJavaScript("didUpdateLocation({coords: {latitude:55.0, longitude:0.0}, timestamp: 1494481126215.0})").當(dāng)然,你注入的 JavaScript 應(yīng)該有 didUpdateLocation 函數(shù)準(zhǔn)備好啟動(dòng)保存的成功處理程序.

                  Now it's time to inject the location back to the requesting JavaScript with webView.evaluateJavaScript("didUpdateLocation({coords: {latitude:55.0, longitude:0.0}, timestamp: 1494481126215.0})"). Of course your injected JavaScript should have didUpdateLocation function ready to launch saved success handler.

                  相當(dāng)長(zhǎng)的算法,但它有效!

                  Quite a long algorithm, but it works!

                  這篇關(guān)于如何防止 WKWebView 重復(fù)請(qǐng)求訪問(wèn)位置的權(quán)限?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!
                • 相關(guān)文檔推薦

                  Help calculating X and Y from Latitude and Longitude in iPhone(幫助從 iPhone 中的緯度和經(jīng)度計(jì)算 X 和 Y)
                  Get user#39;s current location using GPS(使用 GPS 獲取用戶的當(dāng)前位置)
                  IllegalArgumentException thrown by requestLocationUpdate()(requestLocationUpdate() 拋出的 IllegalArgumentException)
                  How reliable is LocationManager#39;s getLastKnownLocation and how often is it updated?(LocationManager 的 getLastKnownLocation 有多可靠,多久更新一次?)
                  CLLocation returning negative speed(CLLocation 返回負(fù)速度)
                  How to detect Location Provider ? GPS or Network Provider(如何檢測(cè)位置提供者?GPS 或網(wǎng)絡(luò)提供商)

                      • <bdo id='ngbwZ'></bdo><ul id='ngbwZ'></ul>
                      • <small id='ngbwZ'></small><noframes id='ngbwZ'>

                          <tbody id='ngbwZ'></tbody>
                        • <i id='ngbwZ'><tr id='ngbwZ'><dt id='ngbwZ'><q id='ngbwZ'><span id='ngbwZ'><b id='ngbwZ'><form id='ngbwZ'><ins id='ngbwZ'></ins><ul id='ngbwZ'></ul><sub id='ngbwZ'></sub></form><legend id='ngbwZ'></legend><bdo id='ngbwZ'><pre id='ngbwZ'><center id='ngbwZ'></center></pre></bdo></b><th id='ngbwZ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ngbwZ'><tfoot id='ngbwZ'></tfoot><dl id='ngbwZ'><fieldset id='ngbwZ'></fieldset></dl></div>

                        • <legend id='ngbwZ'><style id='ngbwZ'><dir id='ngbwZ'><q id='ngbwZ'></q></dir></style></legend>

                          1. <tfoot id='ngbwZ'></tfoot>
                            主站蜘蛛池模板: 久久91av | 99精品视频免费在线观看 | 欧美成人一区二区 | 欧美一级久久 | 国产日韩精品一区 | 亚欧午夜| 理论片午午伦夜理片影院 | 国产成人免费视频网站高清观看视频 | аⅴ资源新版在线天堂 | 国产精品v| 成人精品福利 | 国产二区在线播放 | 日韩欧美在线免费观看 | 日本公妇乱淫xxxⅹ 国产在线不卡 | 精品影院| 中文字幕国产第一页 | 国产日韩欧美 | 日韩 国产 在线 | 97伦理影院| www.中文字幕.com | 免费九九视频 | 日韩精品福利 | 91人人澡人人爽 | 97视频成人 | 久久午夜电影 | 成人福利在线观看 | 欧美国产精品一区二区三区 | 在线一区二区观看 | 国产成人精品一区二区三区网站观看 | 青青草视频网站 | 一区二区三区精品视频 | 韩日一区二区 | 日韩一级免费观看 | 在线看h| 日日干日日 | 中文字幕99 | 日韩三级在线观看 | 国产精品国产三级国产aⅴ无密码 | 又爽又黄axxx片免费观看 | 免费在线观看黄网站 | 黑人巨大精品欧美一区二区免费 |