【问题标题】:ABID in Whatsapp URL schemesWhatsapp URL 方案中的 ABID
【发布时间】:2013-07-16 16:29:25
【问题描述】:

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

我想玩一点它,但我现在面临的问题是我不理解这整个“abid”的东西?!我从哪里获得联系人 ID?那我该怎么用呢?

提前致谢:)

【问题讨论】:

  • 你想做什么?你的目标、产品、目的是什么?
  • 好的,首先我只是想了解它是如何工作的。但想过拥有一些东西,然后直接通过 Whatsapp 分享?现在我只是在我的 iPhone 上的 Safari 中输入 url 方案......

标签: ios url-scheme whatsapp


【解决方案1】:

abid 代表地址簿 ID,它是您与 Whatsapp url 方案一起使用的参数,以便使用您在地址簿中拥有的数据。来自Whatsapp site

要在您的应用中使用 Whatsapp 的 url 方案来发送一条说“Hello World”的文本,您可以执行以下操作(来自网站的示例):

 NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?text=Hello%2C%20World!"];
 if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) 
 {
  [[UIApplication sharedApplication] openURL: whatsappURL];
 }

但是由于您没有发布任何代码,我真的不能说如何使用上面的内容或将它放在哪里。但是,如果需要,您可以随时查看一些有关使用 URL 方案的教程。

希望能回答您的问题!

【讨论】:

  • 不,是的,我完全明白了:) 我不明白地址簿 ID 是如何创建的,也不知道如何使它工作。例如,根据我的理解,它应该是这样的:whatsapp://send?abid=randomname First name: Random Last name: Name
  • O.我不确定在游戏的早期,这只是一天,对吧?但是从外观上看,您的代码可能会起作用……您试一试了吗?否则,请尝试向他们发送电子邮件以查找 Whatsapp(哈哈)。让他们知道缺少他们的文档!
  • 是的,我确实尝试了我的代码,但什么也没发生。只打开了撰写视图,但没有选择我的目标联系人:(
  • 我只会写它们,但会很痛苦:/谢谢 ;)
  • 您是否尝试过仅使用 abid 参数?像whatsapp://send?abid;" or even whatsapp://abid` 或 `whatsapp://send/abid;" 只是感觉这里的黑暗......
【解决方案2】:

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];
    ....
}

这可以在不使用人员选择器的情况下进行编码,只需打开地址簿:

一一比较姓名或姓名与号码的记录——

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;
    }
}

【讨论】:

  • ABID 代表 ABRecordID - 上面的示例有效 - 结果我正在为 URL 本身中的分隔符苦苦挣扎:...它的工作原理如下: QR_whatsapp_string = [NSString stringWithFormat:@"whatsapp ://send?abid=%d;?text=%@;",QR_whatsappABID, outmessage];
  • Constantin,AB记录ID分配给通讯录中的每条记录。它在地址簿源中是唯一的,但会在不同设备之间发生变化。有几种方法可以访问地址簿,但最常见的方法是通过人员选择器控制器,其中您的视图控制器充当代理(上面的示例)。还有一种方法可以使用其中一个地址簿函数来使用地址簿内容填充 NSArray 对象。这很有趣,但与常规的 UIKit 编程相比有一定的难度。
【解决方案3】:

我在这里写了一种批量获取 ABID 的方法:http://n8henrie.com/2014/02/how-to-get-the-abid-for-whatsapp-url-schemes/

基本思路是使用iFunBox 访问手机上的sqlite 数据库,然后运行提取所有ABID 和名称的脚本。

【讨论】:

    【解决方案4】:

    您可以先获取联系人列表,然后选择发送消息给特定的人。

    1. 从通讯录中获取记录id

      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];
          }
      
    2. 获取选定的 RecordID,例如:

      NSString *recordID = [dict objectForKey:@"RecordID"];

    3. 调用 Whats 应用 URL 方案

      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];
      }
      

    【讨论】:

      【解决方案5】:

      请注意,Whatsapp 已删除(在 16 年 3 月期间)URL 架构以打开与特定联系人的对话。

      正如您在他们的 Custom URL Scheme page 上看到的那样,不再有 ABID 参数。

      【讨论】:

        【解决方案6】:

        最近的两个解决方案(2017 年 7 月)

        我在THIS OTHER ANSWER 中发现、测试并引用了两个新的不同解决方案(因为 S.O. 政策我必须放置解决方案的链接,不能重复)。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2014-02-22
          • 2012-02-16
          • 2015-12-23
          • 1970-01-01
          • 1970-01-01
          • 2013-07-31
          • 1970-01-01
          相关资源
          最近更新 更多