iOS URL 方案,完成后返回 Safari
我想实现一个自定义 URL 方案,类似于 mailto 在 Safari 中的工作方式。在我的 html 中,我有一个指向自定义方案的链接(例如 myapp://parms),它将调用定义了 myapp 方案的应用程序。当 myapp 完成后,我想返回 Safari 浏览器页面。如果您有“mailto:”,则邮件应用程序有一个取消按钮。如果你按下它,或者发送,完成后它就会消失,Safari 页面就在那里。
我知道我不应该杀死我的应用程序。如果我尝试,它会返回主页,而不是 Safari。完成后如何让我的自定义方案应用程序消失(隐藏?)以便调用应用程序回来?
I would like to implement a custom URL scheme similar to how mailto works in Safari. In my html I have a link to my custom scheme (e.g., myapp://parms) which will call my app that has the myapp scheme defined. When myapp is done, I want to return to the Safari browser page. If you have a 'mailto:', the mail app has a cancel button. If you push that, or do the send, when done it goes away and the Safari page is there.
I know I am not supposed to kill my app. If I try, it goes back to home and not Safari anyway. How can I have my custom scheme app go away (hide?) when done so the calling app is back?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以让该方案指定一个回调 URL,在执行完任务后打开该 URL。例如,
然后您只需读取回调 URL 并使用
openURL:
即可到达那里。您甚至可以添加一些额外的参数来向调用者指示成功/失败。You could have the scheme specify a callback URL, which you open when you finish performing your task. For example,
Then you would simply read the callback URL and use
openURL:
to go there. You could even add some extra parameters to indicate success/failure to the caller.这里最好的选择是使用自定义方案在 URL 中传递您想要返回的 URL。换句话说,您可以对“回调”URL 进行 URL 编码,并将其作为用于打开应用程序的 URL 中的元素。
当您的应用程序完成其任务时,它会使用打开时收到的数据,使用 [[UIApplication sharedApplication] openURL:yourURL] 方法再次打开 URL。
Your best bet here would be to pass the URL that you want to return to in the URL with the custom scheme. In other words, you would URL encode the 'callback' URL and place it as an element in the URL used to open your application.
When your application completes its tasks, then it uses this data that it received when it was opened to open the URL again using the [[UIApplication sharedApplication] openURL:yourURL] method.