html - iOS 9 中屏幕导航的设备位置路径错误

标签 html ios cordova ios9

在我基于 Cordova 的 iOS 应用程序中,当我尝试从主页导航到下一个屏幕时,它保留在 iOS 9 的主页中,而导航在 iOS 8.4 及更低版本中运行良好。

这是 iOS 8.4 中的路径(工作正常)

file:///var/mobile/Containers/Bundle/Application/EABC-4728-97BF-466B/MyApp.app/www/index-telugu.html#publicinterface

这是 iOS 9.0 中的路径,与假设的路径不同

file:///var/mobile/Containers/Bundle/Application/47CF-A77E-97ACED384A/MyApp.app/www/index-telugu.html#main

如果有人遇到类似问题,请建议我解决此问题的方法

这是我的代码:

    $('#publicinterface_main_id').click(function()
      {

         if (!checkConnection())
        {           
            navigator.notification.alert('Please Check Your Internet Connection');
        }
        else if (!navigator.geolocation) 
        {
            navigator.notification.alert('Please switch on location settings on your mobile');
        }
        else 
        {

            window.location.href = "index-telugu.html#"+$(this).attr('reloadIndex');

            console.log("Path for navigation: : " + window.location.href );

            location.reload();                
            navigator.geolocation.getCurrentPosition(function (p) 
            {
                getAddress(p.coords.latitude,p.coords.longitude);
                $('#pub_HgeoLocation').val(p.coords.latitude+","+p.coords.longitude);
            });

         var places = new google.maps.places.Autocomplete(document.getElementById('pub_geoLocation'));
         google.maps.event.addListener(places, 'place_changed', function () 
            {
                var place = places.getPlace();
                var address = place.formatted_address;
                var longitude = place.geometry.location.lng();
                var latitude = place.geometry.location.lat();
                $('#pub_HgeoLocation').val(latitude+","+longitude)
            });
        }
      });

最佳答案

iOS 9.0 UIWebView(由 Cordova/Phonegap 使用)的一个错误/“功能”是 window.location.hash 的设置是异步的 - 请参阅 this bug report了解详情。请注意,iOS 8+ 上的 Safari 使用 WKWebView 而不是 UIWebView,因此此问题在 iOS 9.0 上的 Safari 浏览器中并不明显

console.log(window.location.hash); // -> "#bar"
window.location.hash = '#foo';

console.log(window.location.hash); 
// -> "#bar" // iOS 9.0 UIWevView
// -> "#foo" // iOS 9.0 WKWebView (Safari) and all other known browsers except

// in all other known browsers at this point window.location.hash will read '#foo'. In iOS9 UIWebView it won't.
if(window.location.hash !== '#foo') {
  // bang: iOS 9 webview
} else {
  // ok: any other browser
}

作为解决方法,您可以尝试使用 window.setTimeout 使设置值 window.location.hash 后的操作异步,从而允许在之前应用该值你用吧。因此,使用上面的代码,尝试如下操作:

window.location.href = "index-telugu.html#"+$(this).attr('reloadIndex');

window.setTimeout(function(){
    console.log("Path for navigation: : " + window.location.href );
    location.reload();    
},0);

关于html - iOS 9 中屏幕导航的设备位置路径错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32990190/

相关文章:

javascript - sqlite同步

javascript - Phonegap (Cordova) iOS 推送通知 onNotificationAPN 事件在后台触发

html - 意外换行

html - 登录/注销 session 未完全正常工作。联合应用程序

html - 如何使用 Bootstrap 使图像响应

ios - 我应该为 LaunchScreen.storyboard 中的图像提供什么尺寸的 @3x、@2x 等?

iphone - Three20 TTMessageController lite替代品

javascript - 在 Cordova 应用程序中捏合以缩放/缩放 iframe

javascript - 复选框未选中,因为复选框在 html 中工作

ios - 快速下拉列表