Share the link through a URL scheme (e.g. via Telegram)

I want to share the link through a URL scheme to say for Telegram.

I created this:

tg: // msg? text = www.example.com?t=12

Link, a telegram opens, but nothing else happens.

I used the same code for Viber and it works:

viber: // forward? text = www.example.com?t=12

and it opens a new message in viber with this text:

www.example.com

In another word, he shortens my url.

Any idea?

+13
source share
8 answers

You can also use the telegram.me sharing link, which returns to the webgram if the telegram application is not installed on the device.

https://telegram.me/share/url?url=<URL>&text=<TEXT>

+27
source

This works with me:

 tg://msg?text=Mi_mensaje&to=+1555999 
+10
source

For the general Telegram distribution:

Goal C:

 if([UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tg://msg?text=test"]){ [UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tg://msg?text=test"] }else{ //App not installed. } 

Swift 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. } 

If you used canOpenURL then you need to add to info.plist

 <key>LSApplicationQueriesSchemes</key> <array> <string>tg</string> </array> 
+4
source

There are different answers here, each of which works in its own way. IE, using tg: instead of http: as a protocol is shorter, but it will cause an error if Telegramme.me is not installed, while the full http: url will redirect to the link with installation instructions for Telegramme.me.

If you want to see all the options for how this is handled, check out this github project in Social-Sharing:

https://github.com/bradvin/social-share-urls#telegramme

+1
source

php:

 <a href="tg://msg?text=<?php echo rawurlencode($gotoURL); ?>">Link</a> 



javascript:

 <script>TEXT="any text or url";</script> <a onclick="window.location='tg://msg?text='+encodeURIComponent(TEXT);">Link</a> 



or very simple:

 tg://msg?text=www.example.com%2F%3Fget%3Dvalue tg://msg?text=www.example.com%2F%3Ft%3D12 
0
source

To check if Telegram is installed, you can do the following (borrowed from the Sharp Whatsapp ShareKit module):

 BOOL isTelegramInstalled = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tg://msg?text=test"]]; 

iOS checks to see if any application is installed that can handle the tg: // scheme, which is Telegram.

0
source

Try using tg: // share :

 <a href="tg://share?url=www.example.com?t=12&text=Check out this url">Link</a> 
0
source

Just tested, it works both when opening the telegram application and the browser if it is not installed:

 let webURL = NSURL(string: "https://t.me/<YOUR ID>")! UIApplication.shared.open(webURL as URL) 
0
source

All Articles