首页 > 解决方案 > 如何使用回退方法在 Xamarin Forms iOS 中实现深度链接

问题描述

我正在开发Xamarin.Forms应用程序。在那方面,我们支持重置密码。为此,当单击忘记密码按钮时,我通过电子邮件收到了忘记密码的链接。当用户单击该链接时,如果安装在浏览器中,我们必须导航到我们的应用程序。

Android中,此行为运行良好。我们正在使用后备方法。请参考以下代码,

if(userAgentString.indexOf('Android')>0){

 window.location="intent://test.com/UV="+UVvalue+"&forgetuserId="+userID+"#Intent;scheme=https;package=com.test.tesApp;S.browser_fallback_url=https://test.com/index.html?UV="+UVvalue+";end"; 

 }

iOS中,我面临如下屏幕截图中的错误,

Safari 浏览器中的错误消息

我们正在使用下面的代码,


function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
  var UVvalue = getUrlVars()["UV"];
  var userID = getUrlVars()["forgetuserId"];
  var PortalValue=getUrlVars()["portal"]
  var isBrowserActive=true;
var userAgentString=navigator.userAgent;
var platform=navigator.platform;
  $('#lbl12').val(userAgentString);
var htmlelement="<label>"+userAgentString+"</label>";
var body=document.getElementsByTagName('body');


window.setTimeout(function(){
if(isBrowserActive==true && userAgentString.indexOf('iPhone')>1){
window.location.href="https://test.com/index.html?UV="+UVvalue;
}
},3500);


if(platform=="Win32" || platform=="Macintel"){
$('#imgLoader').css({'margin-top':'9%'});
window.location.href="https://test.com/index.cfm?mg=CI.ResetforgetPassword&UV="+UVvalue+"&portal="+PortalValue;
}
 function windowClose() {
window.open('','_parent','');
window.close();
}
$(window).blur(function(){
console.log('Window blurred');
isBrowserActive=false; 
if(platform!="Win32" || platform!="Macintel"){

}
window.clearTimeout();
//windowClose();

});
if (userAgentString.indexOf('iPhone')>0){

$('#imgLoader').css({'margin-top':'53%'})
window.location.href="testApp://testApp?UV="+UVvalue+"&forgetuserId="+userID;

}
else if(userAgentString.indexOf('Android')>0){

 window.location="intent://test.com/UV="+UVvalue+"&forgetuserId="+userID+"#Intent;scheme=https;package=com.test.tesApp;S.browser_fallback_url=https://test.com/index.html?UV="+UVvalue+";end"; 

 }

标签: javascriptxamarinxamarin.formsxamarin.iosdeep-linking

解决方案


推荐阅读