简体   繁体   English

将数据快速编码为URL

[英]Swift Encoding data into a URL

So I am trying to store some data within a QR Code. 因此,我试图在QR码中存储一些数据。 I have set my app up so it will scan the QR Code and perform actions based on the content. 我已经设置了我的应用程序,因此它将扫描QR码并根据内容执行操作。 A user must have my app to do this. 用户必须具有我的应用程序才能执行此操作。 If someone didn't have my app, I would like for them to be able to scan the QR code with a normal/third-party QR scanner and be directed my website or my app's AppStore page. 如果有人没有我的应用程序,我希望他们能够使用普通/第三方QR扫描仪扫描QR码,并定向到我的网站或我的应用程序的AppStore页面。 I have found a post from an Android user who describes encoding data into a URL. 我发现一位来自Android用户的帖子描述了将数据编码为URL。 A normal QR scanner would only see the URL and direct the user to a website. 普通的QR扫描器只会看到URL,并将用户定向到网站。 A custom app would decode the URL and extract the data within. 定制应用程序将解码URL并提取其中的数据。 I'm just wondering whether anything like this is possible for Swift? 我只是想知道这样的事情对于Swift可能可行吗?

Thanks in advance. 提前致谢。

Yes, that's trivial, and there's nothing special about Swift or iOS involved in doing it. 是的,这是微不足道的,并且与Swift或iOS无关。

Set up your URL to be a URL that points to your website, with a query parameter that passes the desired data: 将您的网址设置为指向您网站的网址,并带有传递所需数据的查询参数:

http://mywebsite/loaddata?code=aabbccddeeffgghhiijjkkllmmnn

You could encode the data as Base64 encoded output from the encryption algorithm of your choice, so only your apps would be able to decode it. 您可以将数据编码为来自您选择的加密算法的Base64编码输出,因此只有您的应用程序才能对其进行解码。

Encode that as the string in your QR code. 将其编码为您的QR码中的字符串。 Most QR code readers recognize HTTP URLs and will offer to open the link. 大多数QR码阅读器可以识别HTTP URL,并会提供打开链接的机会。

You would then code your website to respond to the URL as desired. 然后,您将对网站进行编码以根据需要对URL进行响应。

Your app could be coded to parse the string from the QR code and ignore everything but the part after the code= . 您的应用可以被编码为解析QR码中的字符串,并忽略除code=之后的所有内容。

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

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