I want to share message from iOS app to whatsApp. For this I am using the following code:
NSString *strMsg = @"whatsapp://send?text=I%20found%20this.%20Check%20it%20out.Deal_1403803205.6628140%20http://MyiOSApp/register.php?deal_id=978&l_id=198&share=true&customer_id=34&domain=5";
NSURL *whatsappURL = [NSURL URLWithString:strMsg];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
[[UIApplication sharedApplication] openURL: whatsappURL];
} else {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"" message:@"WhatsApp is not installed on your device" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
The problem is that the message after the ?
is not sent.
This works: @"whatsapp://send?text=I%20found%20this.%20Check%20it%20out.Deal_1403803205.6628140%20http://MyiOSApp/register.php
But this doesn't :
@"whatsapp://send?text=I%20found%20this.%20Check%20it%20out.Deal_1403803205.6628140%20http://MyiOSApp/register.php?deal_id=978&l_id=198&share=true&customer_id=34&domain=5";
Where am I getting wrong? How do I solve this?
You have to encode it properly, use -
@"whatsapp://send?text=I%20found%20this.%20Check%20it%20out.Deal_1403803205.6628140%20http://MyiOSApp/register.php%3Fdeal_id=978&l_id=198&share=true&customer_id=34&domain=5";
"?" character is not encoded, you need to encode that as above.