1

I’m looking at supporting a custom url scheme in my app. Apple’s documentation notes this format without two forward slashes after the colon: myphotoapp:Vacation?index=1

URL schemes I've seen previously use :// not just : for example myphotoapp://Vacation?index=1. Both seem to work so what’s the difference? Is one more technically correct than the other, one a newer format, or something?

It seems most of Apple's apps use :// according to this unofficial list.

I see there are important differences in parsing the URL with URLComponents that would cause your URL handling code to fail if you were to use them interchangeably:

  • : path is Vacation and host is nil
  • :// path is empty string and host is Vacation
Jordan H
  • 52,571
  • 37
  • 201
  • 351
  • Well, you've answered your own question, so did you want to give it _as_ an answer? – matt Apr 21 '22 at 20:36
  • I only noted one practical difference in implementation. I don't know if one is more technically correct than the other, one a newer format, or something? Which should be used, are they interchangeable, is there semantic meaning behind them, etc – Jordan H Apr 21 '22 at 20:38
  • No, you've explained it yourself. The scheme is the same (the stuff before the first colon). So it will arrive at your app if your app is the exporter of this scheme. When the URL arrives at your app you parse it. So you get to say how you expect the URI to be structured, eg whether it has a host or not. – matt Apr 21 '22 at 21:14
  • Having said all that, don't use a custom scheme at all — use a universal link. – matt Apr 21 '22 at 21:16
  • There's a nice diagram at https://en.wikipedia.org/wiki/Uniform_Resource_Identifier. Really, this question has nothing at all to do with iOS; you're really just wondering about the pieces of a URI, to which the answer is: it's a URI and that's the end of that. – matt Apr 22 '22 at 00:17

0 Answers0