6

I'm trying to use Whatsapp's web API to send text to any valid number (even numbers that are not in my contacts list). If the user has the Whatsapp app installed, it will open. Else, the browser will open.

In Xcode, simulating an iPhone, the problem is that when Safari opens the URL, I get a popup message Safari cannot open the page because the address is invalid. But the address is actually correct and the correct page has loaded behind the popup. I don't understand what the problem is. What do I have to do to not get this popup?

Here's the snippet I'm using in a view-controller:

NSString * plainString = @"https://api.whatsapp.com/send?phone=5511123456789&text=Hello";
NSString * encodedString = [plainString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL * whatsappURL = [NSURL URLWithString:encodedString];

if([[UIApplication sharedApplication] canOpenURL:whatsappURL]) {
    [[UIApplication sharedApplication] openURL:whatsappURL];
}

I also added whatsapp to the LSApplicationQueriesStrings in Info.plist.

  • I started learning Objective-C last week, I have literally no idea how to use other similar answers to solve this.
YosiFZ
  • 7,792
  • 21
  • 114
  • 221
  • 2
    The official WhatsApp documentation advises to use the following URL `https://wa.me/`, however the problem you have described still exists, and I haven't managed to solve it yet. – Tomasz Nazarenko Mar 04 '19 at 11:31
  • Thanks, Tomasz. Unfortunately, I believe I'll have to think of an alternative flow. :( – Daniel Portugal Mar 07 '19 at 15:48
  • this article has some information on it but not working either: https://www.androidpolice.com/2020/04/08/3-ways-to-message-a-number-on-whatsapp-without-adding-them-as-a-contact-first/ – Lance Samaria Nov 25 '20 at 18:48

0 Answers0