Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open whatsapp on iOS with new phone number pre-filled

I know there is scheme to communicate with whatsapp like:

NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?text=Hello%2C%20World!"];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
    [[UIApplication sharedApplication] openURL: whatsappURL];
}

But i can't find how to open whatsapp with a phone number that don't exist before.

It's for a "contatc us" page and if i can only open whatsapp and can't pre fill a phone number, it's useless. I need to be contacted with whatsapp...

Does what I am trying to do exist ?

like image 593
Eric Trikk Avatar asked Jul 03 '15 08:07

Eric Trikk


3 Answers

For phone number pre-filled And Text

   NSURL *whatsappURL = [NSURL URLWithString:@"https://api.whatsapp.com/send?phone=9530670491&text=hello"];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
    [[UIApplication sharedApplication] openURL: whatsappURL];
}

click here for Swift

Check Link For More Details https://www.whatsapp.com/faq/en/general/26000030

like image 98
Varinder Singh iPhone Dev Avatar answered Sep 28 '22 09:09

Varinder Singh iPhone Dev


According to the Whatsapp documentation, you need to actually have the contact in your address book to open a discussion from the url scheme.
So for your question

Does what i try to do exist ?

the answer is: No.

enter image description here

like image 37
Quentin Hayot Avatar answered Sep 28 '22 08:09

Quentin Hayot


You can find the documentation of that whatsapp API above answer. Adding some more point in that based on my own trial :

For communicating direct with the specific contact you need abid of that contact. ABID is that parameter which is automatically generated by the system when you save the contact. So if you dont have number saved in your contact so no way you can open that from your application .

There is one workaround that I have used. When your application load first time in the device , you save the contact us number to the address book . when number saved successfully you will get ABID in the return . you can use that ABID to invoke messaging with that contact.

NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?abid=123&text=Hello%2C%20World!"];
like image 45
V-Xtreme Avatar answered Sep 28 '22 08:09

V-Xtreme