application:openURL:sourceApplication:annotation 返回 NO 与 YES
我正在注册一个应用程序来处理通过 URL 打开的情况,并且与
application:openURL:sourceApplication:annotation
根据 文档 如果您可以支持该 URL,则应返回 YES,如果不支持,则应返回 NO。但这有什么好处呢?如果 URL 格式错误或不受支持,我将返回“否”,但应用程序仍然会打开,就好像没有发生任何问题一样。谁监听 BOOL
返回值以及他们用它做什么?如果 URL 格式错误或不受支持,是否有办法阻止应用程序打开?
I am registering an application to handle being opened via URL and am confused with
application:openURL:sourceApplication:annotation
According to the documentation you should return YES if you can support the URL and NO if not. What good does this do though? I am returning NO in the event that the URL is malformed or unsupported but the app still opens as if nothing went wrong. Who listens for that BOOL
return and what do they do with it? Is there anyway to prevent the app from opening if the URL is is malformed or not supported?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
文档指出,如果成功打开 URI,则返回
YES
;如果未成功打开,则返回NO
。请注意,“打开成功或打开失败”在语义上与“可以或无法打开”不同。不幸的是,没有办法阻止应用程序启动 - 如果它注册了一个模式,那么无论 URI 的其余部分是否格式正确,它都会启动。UIApplication 有两个方法:
canOpenURL:
和openURL:
。第一个仅检查架构是否受支持(不是完整的 URL),后者在其中启动应用程序并返回应用程序委托的结果。因此,回答您的问题:调用
[[UIApplication sharedApplication] openURL:url]
的另一个应用程序是监听您委托结果的应用程序The documentation says that you return
YES
if you successfully opened the URI andNO
if you didn't. Note that "did succeed or did fail to open" is semantically different from "can or cannot open". Unfortunately, there's no way to prevent the app from launching - if it registers a schema then it will be launched regardless of whether the rest of the URI is correctly formatted.UIApplication has two methods:
canOpenURL:
andopenURL:
. First one ONLY checks whether the schema is supported (not the full URL), where's the latter launches the app and returns the result of the application delegate.So to answer your question: the other app who calls
[[UIApplication sharedApplication] openURL:url]
is the one who listens to your delegate's result