Whatsapp URL方案中的ABID

Con*_*cob 4 url-scheme ios whatsapp

昨天Whatsapp更新了他们的iOS应用程序并发布了官方URL方案(api hooks).

我想用它玩一点,我现在面临的问题是我不明白这整个"abid"的事情?!我从哪里获得联系人ID?那我该如何使用呢?

提前致谢 :)

小智 10

ABID代表地址簿记录ID,下面的代码用于获取AB记录ID.它对URL本身中的分隔符的使用很敏感.所以最初的试验没有奏效.要向特定用户发送备注,请使用以下命令:urlstring格式:whatsapp:// send?abid = 123&text = What%20a%20nice%20day - 请注意使用&标记第二个参数.

- (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];
    ....
}
Run Code Online (Sandbox Code Playgroud)

这可以编码而无需使用人员选择器只需打开地址簿:

比较姓名或姓名和号码逐一查看记录 -

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;
    }
}
Run Code Online (Sandbox Code Playgroud)