Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ABID in Whatsapp URL schemes

Yesterday Whatsapp updated their iOS application and released official URL scheme (api hooks).

I wanted to play a little with it and I'm now facing the problem that I don't understand this whole "abid" thing?! Where do I get the contact ID from? And how do I have to use it then?

Thanks in advance :)

like image 290
Constantin Jacob Avatar asked Dec 04 '22 10:12

Constantin Jacob


1 Answers

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. So the initial trials were not working. To send a note to a specific user use this - urlstring format: whatsapp://send?abid=123&text=What%20a%20nice%20day - note the use of & to mark the second parameter.

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

this can be coded without using the people picker simply open the address book:

go through the records one by one comparing the name or name and number -

ABAddressBookRef addressBook = ABAddressBookCreateWithOptions (NULL, error);
int len = (int)ABAddressBookGetPersonCount(addressBook);
for(int i = 1; i < (len + 1); i++) {
    ABRecordRef person = ABAddressBookGetPersonWithRecordID(addressBook, (ABRecordID)i);
    NSString *first, *last;
    if (!person) {
        continue;
    }
    CFStringRef firstc = (CFStringRef)ABRecordCopyValue(person, kABPersonFirstNameProperty);
    if (firstc) {
        CFStringRef lastc =(CFStringRef) ABRecordCopyValue(person, kABPersonLastNameProperty);
        if (lastc) {
            first = [NSString stringWithFormat:@"%@",firstc];
            last =[NSString stringWithFormat:@"%@",lastc];
            CFRelease(lastc);
        }
        CFRelease(firstc);
    }
    if ([[first lowercaseString] isEqualToString:[firstname lowercaseString]] && [[last lowercaseString] isEqualToString:[surname lowercaseString]]) {
        alreadyExists = YES;
        ABID = ABRecordGetRecordID(person);
        break;
    }
}
like image 128
Paulo Avatar answered Dec 26 '22 21:12

Paulo