Search code examples
iosswiftxcodeopera

Open URL in opera crypto browser


When the user taps on a button i want to check if they have opera crypto browser installed. If they have it installed already then i want to open the url in opera crypto browser otherwise they will be redirected to app store to install the app.

The only problem with this code is that it will just open the opera crypto browser app instead of opening and loading the url that i have given. Everything else works fine. Is there anything i am doing wrong in the url or code?

let appScheme = "\("cryptobrowser")://app"
let appUrl = URL(string: appScheme)
if UIApplication.shared.canOpenURL(appUrl! as URL){
    guard let url = URL(string: "cryptobrowser://reizor.com/backup8march/test2.php?token=10000000000000000000") else {return}
    UIApplication.shared.open(url)
}else{
    guard let url = URL(string: "https://apps.apple.com/pk/app/opera-crypto-browser/id1604311726") else {return}
    UIApplication.shared.open(url)
}

Solution

  • So basically what i was doing wrong was that in my if condition where i checked to see if user has cryptobrowser installed and then i converted my url string to URL and opened it using UIApplication.shared.open() function. My URL was wrong.

    I had to change my URL slightly from:

    guard let url = URL(string: "cryptobrowser://reizor.com/backup8march/test2.php?token=10000000000000000000") else {return}
    UIApplication.shared.open(url)
    

    to:

    guard let url = URL(string: "cryptobrowser://open-url?url=https://reizor.com/backup8march/test2.php?token=10000000000000000000") else {return}
    UIApplication.shared.open(url)
    

    Basically adding "open-url?url=https://" after the "cryptobrowser" which is the name of browser i want the link to load in. Because apparently, to open URl in some browsers you just have to write "browserName://yourUrl" and it would open but in most case you have to include "https://" in your URL after writing the name of browser