久久久久久久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)求訪問位置的權(quán)限?

        How to prevent WKWebView to repeatedly ask for permission to access location?(如何防止 WKWebView 重復(fù)請(qǐng)求訪問位置的權(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)求訪問位置的權(quán)限?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我的應(yīng)用中有一個(gè) WKWebView,當(dāng)我開始瀏覽 www.google.com 或任何其他需要定位服務(wù)的網(wǎng)站時(shí),會(huì)出現(xiàn)一個(gè)彈出窗口,詢問是否允許訪問該位置即使我已經(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 代碼來攔截對(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.

                  以下是簡要方案:

                  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)頁請(qǐng)求位置時(shí),此方法將觸發(fā) userContentController(_:didReceive:),以便您的應(yīng)用知道網(wǎng)頁正在請(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)長的算法,但它有效!

                  Quite a long algorithm, but it works!

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

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(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>
                            主站蜘蛛池模板: 久色一区 | 婷婷色综合 | 精品毛片视频 | 大久| 久久国产一区 | 国产精品123区 | 午夜一区 | 久久久久国产一区二区三区 | 艹逼网 | 欧美精品一区二区三区在线四季 | 伊人精品在线 | 中文字幕av免费 | 欧美日韩国产一区二区三区 | 国产日韩免费视频 | 黄色a级一级片 | 欧美激情一区二区三区 | 日韩综合网| 91精品国产91久久久久久吃药 | 国产成人精品一区二区三区在线观看 | 国产成人免费观看 | 青青草原综合久久大伊人精品 | av在线免费观看网址 | 激情欧美日韩一区二区 | 黄网站涩免费蜜桃网站 | 中文二区 | 亚洲免费在线视频 | 中文字幕日韩三级 | 国产精品视频久久久 | 99reav| 亚洲国产aⅴ成人精品无吗 国产精品永久在线观看 | 人人干在线视频 | 精品亚洲一区二区 | 久久久久黄色 | 中文字幕蜜臀av | 99精品视频免费在线观看 | 波多野结衣先锋影音 | 精品久久久久久 | 亚洲国产aⅴ精品一区二区 免费观看av | 一二区成人影院电影网 | 日韩精品一区二区三区视频播放 | 亚洲一区二区三区在线免费观看 |