How to share text via WhatsApp, Viber & Telegram

A few months ago I succeeded achieving the task mentioned in the Title of this post. (on Android & in emulator on Windows which uses desktop versions of WA.V&T-messengers).

To achieve this I used the url-apis, specific for each messenger:

if messenger_str == "telegram" then
		text_to_share_str = string.urlEncode(text_to_share_str)
		url_str = "tg://msg?text=" .. text_to_share_str
	elseif messenger_str == "whatsapp" then
		-- NB no need to urlEncode!
		url_str = "whatsapp://send?text=" .. text_to_share_str
	elseif messenger_str == "viber" then
		-- NB no need to urlEncode!
		url_str = "viber://forward?text=" .. text_to_share_str
	elseif messenger_str == "skype" then
		-- NO url API yet
	elseif messenger_str == "fb_messenger" then
		-- NO url API :
	end

> system.openURL(url_str)

Same code unfortunately does not work on iOS which I have started to explore recently. Viber & WhatsApp just do not show up, and as for Telegram it shares the text such a way, that all the+spaces+become+pluses+which+is+just+annoying. Telegram is the only messenger that requires string.urlEncode function mentioned here:

function string.urlEncode( str )
 
    if ( str ) then
        str = string.gsub( str, "\n", "\r\n" )
        str = string.gsub( str, "([^%w ])",
            function( c )
                return string.format( "%%%02X", string.byte(c) )
            end
        )
        str = string.gsub( str, " ", "+" )
    end
    return str
end

As you can see spaces are changed to pluses on purpose here. OK, let’s fix this like this:

if (system.getInfo("platform") ~= "ios") then
			a_str = string.gsub(a_str, " ", "+")
end

The result - Telegram does not open, too…

One may think that something is not set specifically for iOS, but here is what I use as per manual in Info.plist:

<key>LSApplicationQueriesSchemes</key>
<array>
	<string>whatsapp</string>
	<string>tg</string>
	<string>viber</string>
</array>

If these lines are removed, Telegram still starts and+share+everything+with+plusses, Viber & WhatsApp still do not show up.

I know that there is a special iOS plugin to share staff, but is there a way to fix sharing on iOS?

1 Like

Any ideas?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.