简体   繁体   English

iOS中的URL方案

[英]URL scheme in iOS

I have added an URL scheme to my application. 我已经在应用程序中添加了URL方案。 The URL scheme is testapp:// . URL方案为testapp:// While I entered the text testapp:// in Safari and on hitting return, it launched my application. 当我在Safari中输入文本testapp://并点击返回时,它启动了我的应用程序。

Then I tested with testapp://placeid=12 . 然后我用testapp://placeid=12进行了测试。 This is launching the TestApp in iPad but in iPhone, I am getting Cannot Open Page and I am not able to test. 这将在iPad中启动TestApp,但在iPhone中,我将显示Cannot Open Page并且无法进行测试。

I could pass the placeid=12 as URL query. 我可以通过placeid=12作为URL查询。 But what I would like to know is, why it is not opening in iPhone alone. 但是我想知道的是,为什么它不能仅在iPhone中打开。

Any idea on this? 有什么想法吗?

Note: Irrespective of device types, it seems to be iOS issue. 注意:无论设备类型如何,这似乎都是iOS问题。 This is the behaviour from iOS 6 and above. 这是iOS 6及更高版本的行为。

Could it be that each device is running a different iOS version? 可能是每个设备都运行不同的iOS版本吗?

If so, please take into account some details depending on the version. 如果是这样,请根据版本考虑一些细节。 For example, if you read the Advanced App Tricks , there is a section that may help you: 例如,如果您阅读了高级应用程序技巧 ,则有一部分可以帮助您:

Handling URL Requests 处理URL请求

An app that has its own custom URL scheme must be able to handle URLs passed to it. 具有自己的自定义URL方案的应用程序必须能够处理传递给它的URL。 All URLs are passed to your app delegate, either at launch time or while your app is running or in the background. 在启动时或在应用程序运行时或在后台,所有URL都将传递给您的应用程序委托。 To handle incoming URLs, your delegate should implement the following methods: 要处理传入的URL,您的委托应实现以下方法:

Hope this helps. 希望这可以帮助。 Otherwise, I will really recommend you to stick to the standards . 否则,我会真的建议您遵守标准 It would make your life easier :) 这会让您的生活更轻松:)

It is possibly not working because testapp://placeid=12 is not a valid URL. 由于testapp:// placeid = 12不是有效的网址,因此可能无法正常工作。 You will need a domain address there too, like testapp://localhost/query?placeid=12. 您在那里也需要一个域名,例如testapp:// localhost / query?placeid = 12。 It is possible the '=' character is causing the error. 可能是'='字符导致错误。

I am not able to test it right now so let me know. 我现在无法对其进行测试,所以请告诉我。

As mentioned in the question's note, it is iOS 6's Safari browser behaviour. 如问题注释中所述,这是iOS 6的Safari浏览器行为。 We could not have "=" in the host of the URL while entering in Safari. 在Safari中输入时,URL的主机中不能包含“ =”。

Instead, I solved this problem in the following manner. 相反,我以以下方式解决了这个问题。

Sent the URL in mail, and from Mail, if I click the URL, the app was launched. 发送邮件中的URL,如果我单击URL,则从邮件中发送该应用程序。 But the important point is, I had to parse the URL host to get the value. 但重要的一点是,我必须解析URL主机才能获得该值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM