2

我使用此代码启动 safari 并为客户发布消息:

NSURL *url = [NSURL URLWithString:@"http://www.Mysite.com/testok.html"];
[[UIApplication sharedApplication] openURL: url];

我想要做的是,在启动 safari 几秒钟后,它会自动关闭并返回到我的应用程序。

4

2 回答 2

2

您可以为自定义 URL 方案注册您的应用程序,并从您的网站通过 Java 脚本调用它。有关 URL 方案的更多信息,请查看iOS App Programming Guide

也许更好的解决方案是使用UIWebView.

于 2012-12-29T15:06:43.847 回答
1

使用以下步骤。URLScheme是最佳解决方案。我希望它对你有用。

  1. 在 iPhone Info.plist 中制作URLSchemas如下链接

    客户端(iPhone 项目)设置

  2. 将以下 Html 代码添加到 Safari 浏览器中的重定向按钮。

    <html><head>
    <script type="text/javascript">
    
    function redirection() {
        var userAgent = window.navigator.userAgent;
        if (userAgent.match(/iPad/i) || userAgent.match(/iPhone/i)) {
            window.location = "myapp://"    // This is your app name. make sure it's like URLScheme Name
        }
    }
    </script>
    </head>
    <body>
    Some html page
    <input type="button" value="back" onclick="redirection()"/>
    </body>
    </html>
    
于 2012-12-29T15:51:16.670 回答