从 ABRecordRef 检索即时消息信息

发布于 2024-08-26 20:16:02 字数 929 浏览 6 评论 0原文

我正在尝试从 iOS 上现有的 AddressBook 联系人获取即时消息帐户信息。我浏览联系人并获得具有即时消息传递价值的联系人,但我无法读取 jabber 地址。

abArray = (NSArray *)ABAddressBookCopyArrayOfAllPeople(ABAddressBookCreate());

for(int i=0 ; i<[abArray count];i++)
{
  ABRecordRef record = [abArray objectAtIndex:i];

  ABMutableMultiValueRef multi = ABRecordCopyValue(record, kABPersonInstantMessageProperty);

  for(CFIndex x=0;x<ABMultiValueGetCount(multi);x++)
  {
   CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(multi, x);
   CFStringRef jabber = CFDictionaryGetValue(dict, kABPersonInstantMessageServiceJabber);

   if(CFDictionaryContainsKey(dict, kABPersonInstantMessageServiceJabber))
   {
    NSLog(@"yes");
   }
   else {
    NSLog(@"no");
   }

   // only to make it possible to log to console   
   NSString *jaab = (NSString *)jabber;
   NSLog(@"jabber adress: %@" , jaab);
   }
   CFRelease(dict);
  }
}

我做错了什么?

I'm trying to get the instant message account information from existing AddressBook contacts on iOS. I walk through the contacts and I get the contacts which have an instant messaging value, but I can't read the jabber-address.

abArray = (NSArray *)ABAddressBookCopyArrayOfAllPeople(ABAddressBookCreate());

for(int i=0 ; i<[abArray count];i++)
{
  ABRecordRef record = [abArray objectAtIndex:i];

  ABMutableMultiValueRef multi = ABRecordCopyValue(record, kABPersonInstantMessageProperty);

  for(CFIndex x=0;x<ABMultiValueGetCount(multi);x++)
  {
   CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(multi, x);
   CFStringRef jabber = CFDictionaryGetValue(dict, kABPersonInstantMessageServiceJabber);

   if(CFDictionaryContainsKey(dict, kABPersonInstantMessageServiceJabber))
   {
    NSLog(@"yes");
   }
   else {
    NSLog(@"no");
   }

   // only to make it possible to log to console   
   NSString *jaab = (NSString *)jabber;
   NSLog(@"jabber adress: %@" , jaab);
   }
   CFRelease(dict);
  }
}

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请叫√我孤独 2024-09-02 20:16:02
for(int i=0 ; i<[abArray count];i++)
{
    ABRecordRef record = [abArray objectAtIndex:i];
    ABMutableMultiValueRef multi = ABRecordCopyValue(record, kABPersonInstantMessageProperty);

    for(CFIndex x=0;x<ABMultiValueGetCount(multi);x++)
    {
        CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(multi, x);
        CFStringRef jabber;


        //Use this piece of code to print the dict to log and check

        NSDictionary *nsdict = (NSDictionary *)dict;
        NSString *jabberID = [NSString stringWithString:@""];
        NSLog(@"Dict: %@", nsdict);
        if([[nsdict valueForKey:@"service"] isEqualToString:@"Jabber"]){
            jabberID = [nsdict valueForKey:@"username"];
        }
        //Code to print dict to log ends here. Comment the whole piece if not needed.


        if(CFStringCompare((CFStringRef)@"jabber", CFDictionaryGetValue(dict, @"service"), 0))
        {
            NSLog(@"yes");
            jabber = CFDictionaryGetValue(dict, @"username");

            // only to make it possible to log to console  
            NSString *jaab = (NSString *)jabber;
            NSLog(@"jabber adress: %@" , jaab);
        }
        else {
            NSLog(@"no");
        }

    }
    //CFRelease(dict);
}
for(int i=0 ; i<[abArray count];i++)
{
    ABRecordRef record = [abArray objectAtIndex:i];
    ABMutableMultiValueRef multi = ABRecordCopyValue(record, kABPersonInstantMessageProperty);

    for(CFIndex x=0;x<ABMultiValueGetCount(multi);x++)
    {
        CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(multi, x);
        CFStringRef jabber;


        //Use this piece of code to print the dict to log and check

        NSDictionary *nsdict = (NSDictionary *)dict;
        NSString *jabberID = [NSString stringWithString:@""];
        NSLog(@"Dict: %@", nsdict);
        if([[nsdict valueForKey:@"service"] isEqualToString:@"Jabber"]){
            jabberID = [nsdict valueForKey:@"username"];
        }
        //Code to print dict to log ends here. Comment the whole piece if not needed.


        if(CFStringCompare((CFStringRef)@"jabber", CFDictionaryGetValue(dict, @"service"), 0))
        {
            NSLog(@"yes");
            jabber = CFDictionaryGetValue(dict, @"username");

            // only to make it possible to log to console  
            NSString *jaab = (NSString *)jabber;
            NSLog(@"jabber adress: %@" , jaab);
        }
        else {
            NSLog(@"no");
        }

    }
    //CFRelease(dict);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文