CanOpenURL to open other applications - does not work on simulator

I am trying to open Yelp from my application which has 8.1 deployment target

The problem I am facing is my code that is evaluating the simulator incorrectly. My device is iOS 10.3 and it works fine there (Yelp opens), but I need to check if this works on the simulator for older iOS versions!

    let urlStr: String = "yelp://"
    let url = URL(string: urlStr)
    if UIApplication.shared.canOpenURL(url!) {
        print("can open")
        if #available(iOS 10.0, *) {
            print("10")
            UIApplication.shared.open(url!, options: [:], completionHandler: nil)
        } else {
            print("NOT 10")
            UIApplication.shared.openURL(url!)
        }
    }
    else {
        // Can not open URL
        print("can not open url")
    }

      

While in the simulator (iOS 8.1) the following information is displayed on the console:

can open
NOT 10

      

However, this is wrong! Yelp is not installed on the simulator but will not print("can not open url")

evaluate if it does

Here's my URLTypes / LSApplicationQueriesSchemes in info.plist.

Here are my URLTypes / LSApplicationQueriesSchemes in info.plist.

Is there something wrong with my code above? How can I properly check if Yelp is open on a simulator where can I QA for various iOS builds (since 8.1)? Thanks to friends.

+3


source to share


1 answer


It returns true

because there is an element in your url schemes yelp

, basically the system is trying to open your own application when you call openURL

. Modify this item and retest.



+5


source







All Articles