How to Implement deeplinking in Xamarin Forms iOS using fallback method

2020-02-27 javascript xamarin xamarin.forms xamarin.ios deep-linking

I'm developing the Xamarin.Forms application. In that, we are having the support to resetting the password. For that, when clicking the forgot password button, I received my forgot password link via email. When user clicking that link, we have to navigate to our application if installed else to browser.

In Android, this behavior is working fine. We are using fallback method. Please refer the below code,

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"; 

 }

In iOS, I'm facing the error like in the screenshot below,

Error message in the Safari browser

We are using the below code,


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"; 

 }

Answers

Related