【问题标题】:Shorten URL in Swift iOS with your custom website domain name使用您的自定义网站域名缩短 Swift iOS 中的 URL
【发布时间】:2021-10-11 20:10:25
【问题描述】:

当用户共享商店时,我想缩短我应用中的共享 URL。我想要一种方法或 API,让我可以缩短 URL 以使其看起来干净但使用我的网站名称。

例如:

longURL:"https://example.com?x=somevalue&y=someothervalues"

然后,当我使用 API 或方法缩短 URL 时,它会生成一个类似于以下内容的小 URL:"https://mywebsite.com/shortenedURLcode"

这是我的代码:

link = URL(string: "https://mywebsitename.com/share/?shop="+concatenate(getKey!,"&title="+shopName.text!.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!,"&desc="+summary.text!.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!,"&img="+profileImgURL))

我想用我网站的主机名缩短上述链接。

我该怎么做?

【问题讨论】:

  • 域名会一直保持不变,还是会根据店铺或其他因素而有所变化?

标签: ios swift api clean-urls short-url


【解决方案1】:

以下是缩短 URL 的两个选项:

Bitly API

一个选项 Bitly 的 API,它将允许您发出返回符合上述标准的缩短链接的请求。

看来要达到您寻求的结果,您必须提出两个请求:一个接收link with custom domain,第二个接收customize the "back half"(请参阅超链接文本中的revenant API 文档)。

请求 #2 的结果将包含您完全自定义的链接。

品牌重塑 API

在我看来,更好的选择是 Rebrandly。虽然我个人没有任何使用 Rebrandly 产品的经验,但我会推荐这个选项,因为它有一个慷慨的免费套餐让你开始。

最重要的是,整个缩短的链接可以在一个请求中制定。会注意到,Bitly 所谓的“后半部分”被 Rebrandly 称为“斜线标签”,但这些术语都指的是完全相同的东西。

API 文档可以在 here 找到。

【讨论】:

    猜你喜欢
    • 2018-01-10
    • 2017-11-06
    • 2015-09-10
    • 1970-01-01
    • 2010-10-31
    • 1970-01-01
    • 2019-05-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多