iOS: Can openURL ever be nil?
For -[UIApplicationDelegate application:openURL:sourceApplication:annotation:]
, can the URL ever be nil
? I'm asking because I saw someone put in a check if (url) // ...
, but isn't that unnecessary? I.e., doesn't this method always get called with a non-nil NSURL
argument for开发者_StackOverflow openURL
?
Assuming an external invocation (ie from another app trying to open yours), then I would assume it is non-nil, however perhaps (unlikely I know) you call it internally in which case it might be?
Assumptions however are dangerous!
It would therefore seem prudent to sanity check the value before doing something that might cause a crash should the value be nil.
Seems OK to check if you ask me.
According to Apple Documentation, the url parameter is:
A object representing a URL (Universal Resource Locator). See Apple URL Scheme Reference for Apple-registered schemes for URLs.
You have to register your application to accept specific URLs.
This article shows how it is done.
This would lead me to believe that this method would not be called unless it adhered to a URL Schema specified by the application.
If it is being called internally, than you would know whether you would need to check for nil or not. As for an outside application calling it, I can't see how that would happen.
精彩评论