1

I need to know if you can open a contact from whatapps with "abid=+2827272727" command.

NSURL *whatsappURL = [NSURL
URLWithString:@"whatsapp://send?abid=+2827272727&text=Hola!"];
if ([[UIApplication sharedApplication] canOpenURL:whatsappURL]) {
    [[UIApplication sharedApplication] openURL:whatsappURL];
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579

1 Answers1

1

Yes you can, but be aware that abid is not the Contacts Phone Number. It is ABRecordGetRecordID

Try this code to open whatsapp with the contact named "Your Name" in your address book.

    // Fetch the address book
    ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL,NULL);
    dispatch_semaphore_t sema = dispatch_semaphore_create(0);
    ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
        dispatch_semaphore_signal(sema);
    });
    dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);

    // find user
    CFStringRef searchQuery = CFSTR("Your Contact Name");

    CFArrayRef array = ABAddressBookCopyPeopleWithName (addressBook,searchQuery);
    int items = CFArrayGetCount(array);
    NSLog(@"found %i persons",items);

    int abid = 0;
    for (int i = 0; i < items; i++)
    {
        ABRecordRef person = CFArrayGetValueAtIndex(array, i);
        abid = ABRecordGetRecordID(person);
        NSLog(@"found person %i ",abid);
        break;
    }

    if (abid > 0)
    {
        NSString* url = [NSString stringWithFormat:@"whatsapp://send?abid=%i&text=Hola",abid];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
    }
JeanLuc
  • 4,783
  • 1
  • 33
  • 47