3

I'm trying to open Yelp from within my App that has a deployment target of 8.1

The problem I'm facing is my code is not properly evaluating on the simulator. My device is iOS 10.3, and it works fine on there (Yelp opens), but I need to be able to check to see if this works on the simulator for older versions of iOS!

    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 prints to the console:

can open
NOT 10

However, this is wrong! Yelp is not installed on the simulator - but if that's the case, wouldn't print("can not open url") evaluate??

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

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

Is there anything wrong with my code above? How can I properly test the opening of Yelp on the simulator, where I'm able to QA on various builds of iOS (starting at 8.1)? Thanks friends.

Joe
  • 3,772
  • 3
  • 33
  • 64
  • Out of curiosity - what happens on the simulator after the call to `openURL`? Also, it is good practice to keep at least one device with the lowest version of the system that you support, if possible. – Losiowaty Apr 14 '17 at 20:49
  • Do you have the same problem with simulators of iOS 9.x or 10.x? – rmaddy Apr 14 '17 at 20:50
  • Can you try doing `Reset Content and Settings` in your simulator then run your app and see if it will give same result? – janusfidel Apr 14 '17 at 20:54
  • @Losiowaty - Nothing happens (although nothing SHOULD happen). But as I mentioned in my question, "can open" should not be printing to the console, as Yelp is not on the simulator. – Joe Apr 14 '17 at 20:54
  • @rmaddy - Yes. Same issue persists throughout 8/9/10. – Joe Apr 14 '17 at 20:56
  • @janusfidel - Unfortunately, same result :( "can open" is still printing, when it shouldn't be. – Joe Apr 14 '17 at 21:04

1 Answers1

5

It returns true because in your URL Schemes, you have an item yelp, basically the system tries to open your own app when you call openURL. Change that item and test again.

janusfidel
  • 8,036
  • 4
  • 30
  • 53
  • Good catch. I saw that and didn't make the connection. I focused more on the correct entry for `LSApplicationQueriesSchemes`. – rmaddy Apr 14 '17 at 21:35
  • A ha! So you're saying to just get rid of item 0 (yelp) specifically? – Joe Apr 14 '17 at 21:51
  • 1
    @Joe Yes, the one in the `URL Types` section. You are declaring that your own app responds to the `yelp` URL scheme. Apple would end up rejecting your app for that. If your app needs its own custom URL scheme, specify your own custom scheme, don't use the one for Yelp's app. – rmaddy Apr 14 '17 at 21:53
  • 1
    @Joe I am not sure If you added that because you want to register your app in URL Scheme so that other apps can open it. If that is not your intention for adding that, then yes you can delete that. – janusfidel Apr 14 '17 at 21:55
  • @rmaddy - Goodness. Thanks for pointing that out to me! I was misunderstood. I thought URL types was for permission purposes post iOS9. I'm not interested in registering my own URL scheme (just want to open Yelp! :) ). I can just delete that entire URL Types section, correct? – Joe Apr 14 '17 at 21:59
  • @Joe The entry under `LSApplicationQueriesSchemes` is the list of schemes you wish to use with `openURL` starting with iOS 9. Keep that one. – rmaddy Apr 14 '17 at 22:02
  • You both rock! I removed the entire URL Types section from the info.plist, left in the 'LSApplicationQueriesSchemes' section, and all seems to be working just fine in 8.1+. The proper print statements are evaluating now. Thanks for the help! – Joe Apr 14 '17 at 22:04