Pavan Pavan - 2 years ago 186
Swift Question

How to move user on specific contacts chat screen in whatsapp from our app?

I wanted to integrate below functionality :

I am passing one contact number of user. so if that contact number is already exist and directly open that user chat screen when i pressed on whatsapp button in my app.

if that contact no is not exist in addressbook then first stored this contact in addressbook and then open that contact chat screen in whatsapp (with refreshing contacts so i will get name of that person on whatsapp chat screen).

i have done below task :

if contact is not exist then it first stored in addressbook and then move to whatsapp. if second time when i pressed again whatsapp button then its check that contact is exist or not. if already saved then fetch its record identifier and passed with whatsapp url scheme.

The main problem is that its just move on whatsapp app on contact list not open specific chat screen of user.

Note : This thing works perfectly in android so i hope that its also possible to integrate in iOS/swift app.

Answer Source

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"];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download