far*_*985 18 url-scheme ios swift
我想通过URL方案分享一个链接,比如电报.
我创造了这个:
tg:// msg?text = www.example.com?t=12
链接,打开电报,但没有其他事情发生.
我在Viber上使用了相同的代码,它的工作原理如下:
viber:// forward?text = www.example.com?t=12
它在viber中用这个文本打开一条新消息:
www.example.com
换句话说,它削减了我的网址.
任何的想法?
Moh*_*far 34
如果设备上没有安装电报应用程序,您还可以使用telegram.me共享链接,该链接可以回退到webogram.
https://telegram.me/share/url?url=<URL>&text=<TEXT>
Mar*_*iam 10
这对我有用:
tg://msg?text=Mi_mensaje&to=+1555999
Run Code Online (Sandbox Code Playgroud)
您有以下 URL 选项...
https://t.me/share/url?url={url}&text={text}
https://telegram.me/share/url?url={url}&text={text}
tg://msg_url?url={url}&text={text}
Run Code Online (Sandbox Code Playgroud)
如果您想确认,这里是官方 API 来源:Core.Telegram.org: Widgets -> Sharing Button。
如果您有兴趣观看跟踪这些 URL 的项目,请查看我们!:https : //github.com/bradvin/social-share-urls#telegramme
对于电报分享:
目标 C:
if([UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tg://msg?text=test"]){
[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tg://msg?text=test"]
}else{
//App not installed.
}
Run Code Online (Sandbox Code Playgroud)
斯威夫特 3.0:
let urlString = "tg://msg?text=test"
let tgUrl = URL.init(string:urlString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)!)
if UIApplication.shared.canOpenURL(tgUrl!)
{
UIApplication.shared.openURL(tgUrl!)
}else
{
//App not installed.
}
Run Code Online (Sandbox Code Playgroud)
如果你使用过canOpenURL,那么需要在info.plist中加入
<key>LSApplicationQueriesSchemes</key>
<array>
<string>tg</string>
</array>
Run Code Online (Sandbox Code Playgroud)
您可以使用该链接telegram.me,该链接将提供一个带有警报的预览页面,请求在应用程序中打开该链接。
https://telegram.me/share/url?url=<URL>&text=<TEXT>
Run Code Online (Sandbox Code Playgroud)
第二个选项是直接调用应用程序链接:
tg://msg_url?url=<url>&text=<encoded-text>
Run Code Online (Sandbox Code Playgroud)
我特别喜欢第二个选项,它也适用于桌面应用程序。
小智 3
PHP
<a href="tg://msg?text=<?php echo rawurlencode($gotoURL); ?>">Link</a>
Run Code Online (Sandbox Code Playgroud)
JavaScript
<script>TEXT="any text or url";</script>
<a onclick="window.location='tg://msg?text='+encodeURIComponent(TEXT);">Link</a>
Run Code Online (Sandbox Code Playgroud)