iosswiftswift2whatsapp

How to open specific contact's chat screen in WhatsApp from our app?


I wanted to integrate below functionality:

I am passing one contact number of a user. If that contact number already exists, directly opens that user's chat screen when I press on WhatsApp button in my app.

If that contact does not exist in the address book, then first, store this contact in the address book and then open that contact's chat screen in WhatsApp (with refreshing contacts so I will get the name of that person on WhatsApp chat screen).

I have done below task:

If contact does not exist, then it first stored in the address book and then move to WhatsApp. If I press the WhatsApp button again for the second time, then it checks that contact if it exists or not. If it's already saved, then fetch its record identifier and passed with WhatsApp URL scheme.

The main problem is that it just moves to WhatsApp's contact list, but does not open specific chat screen of the user.

Note: This thing works perfectly in Android, so I hope that it's also possible to integrate into iOS/Swift app.


Solution

  • Simply Append with ABID with your whatsapp url scheme and call this its worked.

    ABID stands for the Address book Record ID,the code below works to get the AB Record ID. It is sensitive to the use of delimeters in the URL itself.

    To send a note to a specific user use this - urlstring format: whatsapp://send?abid=12&text=Hello%20World - note the use of & to mark the second parameter.

    - (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController    *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
    {   
        ARecordID  = (ABRecordID)ABRecordGetRecordID(person);
        ....
        whatsapp_string = [NSString stringWithFormat:@"whatsapp://send?abid=%d&text=%@;",ARecordID, "hello"];
        ....
    }