Tuesday, May 30, 2023
HomeiOS Developmentjavascript - The right way to stop iOS deep hyperlink from redirecting...

javascript – The right way to stop iOS deep hyperlink from redirecting to App Retailer when app is already put in?


I’m attempting to hit deep-link perform from browser for Android & IOS utility.
the perform checks the appliance put in or not.
if utility has put in they opened the app else they ship me to Appstore or Playstore to obtain the app.

all the things works wonderful with this code. and 100% working in android.
however in IOS the perform examine the appliance will not be put in they redirect me to Appstore hyperlink. it’s wonderful.
however the utility is put in they opened the App and in addition redirect me to Appstore.

is there any method to resolve this glitch?

here is the code..

async perform checkAppInstalled() { 

 var deeplinkUrl = deeplink + "/" +declineworkdefaultcarid; 
 const iosFallbackUrl = "https://apps.apple.com/pk/app/prod/id16";

 attempt {
   await openDeepLink(deeplinkUrl);
 } catch (error) {
   window.location.href = iosFallbackUrl;
 }

}




perform openDeepLink(deepLinkUrl) { 
 const iosFallbackUrl = "https://apps.apple.com/pk/app/prod/id16"; 
 return new Promise((resolve, reject) => { 
  const anchor = doc.createElement("a"); 
  anchor.href = deepLinkUrl;

  const clickHandler = () => {
    resolve();
  };

  const errorHandler = () => {
    reject(new Error("Deep hyperlink failed"));
    window.location.href = iosFallbackUrl;
  };

  anchor.addEventListener("click on", clickHandler);
  anchor.addEventListener("error", errorHandler);

  doc.physique.appendChild(anchor);
  anchor.click on();

  setTimeout(() => {
    doc.physique.removeChild(anchor);
    reject(new Error("Deep hyperlink timeout"));
    window.location.href = iosFallbackUrl;
  }, 3500); // Regulate the timeout length as wanted
  });

}



// predominant perform 

const deeplinkfunc = async (e) => { 
const isAndroid = /Android/.take a look at(navigator.userAgent); 
const isiOS = /iPhone|iPad|iPod/.take a look at(navigator.userAgent); var scheme;

var deeplinkUrl = deeplink + "/" + declineworkdefaultcarid;
var androidDeepLink = deeplink + "/" + declineworkdefaultcarid;


if (isAndroid) {

  scheme = androidDeepLink;

} else if (isiOS) {

  scheme = deeplinkUrl;

} else {
  //  that is for net utility
  declinedServices();
  setdeclineuserwebstate(true);
}

const androidFallbackUrl = "https://play.google.com/retailer/apps/particulars?id=a1212";
const iosFallbackUrl = "https://apps.apple.com/pk/app/prod/id16";

if (isAndroid) {

  window.location.href = scheme;
  setTimeout(() => {
    window.location.href = androidFallbackUrl;
  }, 250);

} else if (isiOS) {

  checkAppInstalled();

} else {
  console.error("Unsupported system sort");
}

};

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments