问题
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 :)
回答1:
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;
}
}
回答2:
Please note that Whatsapp has removed (during March '16) the URL Schema to open a conversation with a specific contact.
As you can see on their Custom URL Scheme page there is no more the ABID parameter.
回答3:
I've written up one way to get the ABIDs in bulk here: http://n8henrie.com/2014/02/how-to-get-the-abid-for-whatsapp-url-schemes/
The basic idea is to use iFunBox to access an sqlite database on your phone, then run a script that extracts all of the ABIDs and names.
回答4:
Two recent solutions (July 2017)
I've found, tested and refered two new different solutions in THIS OTHER ANSWER (because S.O. policies I had to put a link to the solution, no duplicates).
回答5:
abid stands for Adress Book ID and it is a parameter that you use with the Whatsapp url scheme in order to use data that you have in your address book. From the Whatsapp site.
To use the url scheme for Whatsapp in your app to send a text saying "Hello World" you would do something like this (example from the site):
NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?text=Hello%2C%20World!"];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL])
{
[[UIApplication sharedApplication] openURL: whatsappURL];
}
But since you posted no code, I can't really say how to use the above or where to put it. But you could always check out some tutorials on using URL schemes if you need to.
Hope that answers your question!
回答6:
For abid you can get contact list and then select to send message to a particular person.
Get Record id from AddressBook
contactList=[[NSMutableArray alloc] init]; CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(m_addressbook); CFIndex nPeople = ABAddressBookGetPersonCount(m_addressbook); for (int i=0;i<nPeople;i++) { NSMutableDictionary *dOfPerson=[[NSMutableDictionary alloc] init]; ABRecordRef ref = CFArrayGetValueAtIndex(allPeople,i); NSNumber *recordId = [NSNumber numberWithInteger:ABRecordGetRecordID(ref)]; [dOfPerson setObject:recordId forKey:@"RecordID"]; [contactList addObject:dOfPerson]; }
Get Selected RecordID like:
NSString *recordID = [dict objectForKey:@"RecordID"];
Call Whats app URL Scheme
NSString *str = [NSString stringWithFormat:@"whatsapp://send?text=Whenitize&abid=%@",recordID]; NSLog(@"%@", str); NSURL *whatsappURL = [NSURL URLWithString:str]; if ([[UIApplication sharedApplication] canOpenURL:whatsappURL]) { [[UIApplication sharedApplication] openURL:whatsappURL]; } else { [[[UIAlertView alloc] initWithTitle:@"" message:@"Please install What's App in your device." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show]; }
来源:https://stackoverflow.com/questions/17711325/abid-in-whatsapp-url-schemes