Sendoa Sendoa - 1 year ago 166
Objective-C Question

Sending an URL alongside text using WhatsApp URL scheme

I'm trying to send some text accompanied by an URL using WhatsApp's custom URL scheme. There's apparently only one valid parameter for this purpose:


NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?text=Hello%2C%20World!"];

The problem comes when I want to append my own URL to that text. I opted to encode it using this:

NSString *encodedURLString = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(
kCFStringEncodingUTF8 ));

The URL is sent to WhatsApp alongside the text but it doesn't get decoded on the WhatsApp's side:

WhatsApp not decoding the URL

Any ideas? Thank you!

Answer Source

You're approaching it correctly, but it appears that the URL is being double-encoded. Make sure both the message and URL is only encoded once.

Using your same encoding method, you can do something like so:

NSString *urlAbsoluteString = @"Hello World!";
NSString *encodedURLString = ...

That should give you the URL to execute:


That makes its way into WhatsApp just like you'd expect. (I verified to make double sure.)