Reputation: 7774
I'm having trouble understanding how this method works.
From the documentation, it specifies:
canOpenURL: Returns whether an application can open a given URL resource.
- (BOOL)canOpenURL:(NSURL *)url
Parameters url A URL object that identifies a given resource. The URL’s scheme—possibly a custom scheme—identifies which application can handle the URL.
Return Value NO if no application is available that will accept the URL; otherwise, returns YES.
Discussion This method guarantees that that if openURL: is called, another application will be launched to handle it. It does not guarantee that the full URL is valid.
Availability Available in iPhone OS 3.0 and later. Declared In UIApplication.h
Specifically, if it:
guarantees that that if openURL: is called, another application will be launched to handle it.
Then for example, if I pass in tel://HELLOWORLD
, it returns YES
, and when I'm attempting to openUrl
, the phone application is not calling it. Nothing happens, so I'm assuming the full url is not valid when attempting to dial the number.
I understand that it does not validate the full URL, but by design, why is it not showing me an error or something if I am unable to dial the number?
Basically what I'm wondering is: what is it exactly validating?
I'm not convinced that it just checks for the handler type and the apps that support that specific handler (tel://
in this case will not work for iPod Touch for example.).
Upvotes: 1
Views: 6904
Reputation: 19926
Validation is not the purpose of this function. It is only checking whether there is an application registered for this url scheme.
E.g. on the iPod touch or iPad, there is no phone app, and thus canOpenURL
will return NO
for tel:
urls.
Or if you ask it for an url with the foo:
scheme, it will return true if the user device has any App installed that claims to handle this scheme.
It can't possible validate the url, because it doesn't know anything about the foo
scheme or whatever scheme the next app developer comes up with. And you won't want to load the App to validate the url at this point, either.
Upvotes: 12
Reputation: 22116
From the docs:
Discussion
This method guarantees that that if
openURL:
is called, another application will be launched to handle it. It does not guarantee that the full URL is valid.
Upvotes: 1