是的,你可以,但請注意,阿比德不是聯繫人電話號碼。 這是ABRecordGetRecordID
試試這個代碼來打開你的地址簿中名爲「你的名字」的聯繫人的WhatsApp。
// 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]];
}