gpt4 book ai didi

ios - 无法在 iPhone 版 Whatsapp 上分享网址

转载 作者:行者123 更新时间:2023-11-30 13:43:38 27 4
gpt4 key购买 nike

我有下面的代码,我用它来使用whatsapp url方案在whatsapp上共享url,但是当我这样做时,我在whatsapp消息屏幕上看到空消息。

let itunesLink = "http://google.com";
let text = itunesLink.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLPathAllowedCharacterSet());
let url = NSURL(string: "whatsapp://send?text=\(text!)")
UIApplication.sharedApplication().openURL(url!);

当此代码运行时,我会看到联系人,在选择 Whatsapp 帐户选项后,我看不到网址并看到空屏幕。

最佳答案

我总是很困惑为什么这些集合中有这么多允许的字符。我怀疑您可能需要添加更多百分比编码。这是我用来对嵌入 URL 中的 URL 进行编码的方法:

let set = NSCharacterSet(charactersInString: ".-0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~")
let text = itunesLink.stringByAddingPercentEncodingWithAllowedCharacters(set)

由于“/”是 URL 路径中允许的字符,因此 URLPathAllowedCharacterSet 包含“/”,并且 itunesLink 中的“/”不会进行百分比编码,使用原始程序。这可能会让 Whatsapp 感到困惑。这确实让我感到困惑。

关于ios - 无法在 iPhone 版 Whatsapp 上分享网址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35249926/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com