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.