HomeiOS Developmentjavascript - Find out how to stop iOS deep hyperlink from redirecting...

javascript – Find out how to stop iOS deep hyperlink from redirecting to App Retailer when app is already put in?


I’m making an attempt to hit deep-link operate from browser for Android & IOS utility.
the operate 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.

the whole lot works advantageous with this code. and 100% working in android.
however in IOS the operate verify the appliance will not be put in they redirect me to Appstore hyperlink. it’s advantageous.
however the utility is put in they opened the App and likewise redirect me to Appstore.

is there any approach to remedy this glitch?

this is the code..

async operate 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;
 }

}




operate 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); // Alter the timeout period as wanted
  });

}



// essential operate 

const deeplinkfunc = async (e) => { 
const isAndroid = /Android/.check(navigator.userAgent); 
const isiOS = /iPhone|iPad|iPod/.check(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 internet 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