0

I can't get the social profile informations (twitter, facebook) at CFArrayGetValueAtIndex if I try it. Every other information like name, number, www I'm getting it. I have created a vCard with ABPersonCreateVCardRepresentationWithPeople, if I try a output I'm getting the Info like:

BEGIN:VCARD
VERSION:3.0
PRODID:-//Apple Inc.//iOS 10.7.5//EN
N:lastname;Firstname;;;
FN:Firstname lastname
ORG:company;
TITLE:Jobtitle
item1.EMAIL;type=INTERNET;type=pref:my@mail.com
item1.X-ABLabel:Global
TEL;type=IPHONE;type=CELL;type=VOICE;type=pref:049651651561
item2.URL;type=pref:Www.com.com
item2.X-ABLabel:_$!<HomePage>!$_
X-SOCIALPROFILE;type=twitter;x-user=Twitteracc:http://twitter.com/Twitteracc
X-SOCIALPROFILE;type=facebook;x-user=Face.book:http://www.facebook.com/Face.book
END:VCARD

The Code I've tried to get the Information back is:

ABAddressBookRef book = ABAddressBookCreate();
ABRecordRef defaultSource = ABAddressBookCopyDefaultSource(book);

CFDataRef vCardData = (__bridge CFDataRef)[vCardString dataUsingEncoding:NSUTF8StringEncoding];
CFArrayRef vCardPeople = ABPersonCreatePeopleInSourceWithVCardRepresentation(defaultSource, vCardData);
ABRecordRef person = CFArrayGetValueAtIndex(vCardPeople, 0);

...person don't have social information. Later I've tried to append the social information, also a mistake. It works only if I create a new ABPersonCreate()...so it is my mistake? Or it won't work yet? Any ideas?

kurtanamo
  • 1,808
  • 22
  • 27

1 Answers1

0

it will be a bug in the SDK...so the only one thing you can do is to separate the string and create a new ABPerson - with ABPersonCreate() - just look at my code - it will work for me.

-(NSMutableDictionary *)getMyVCardObjects:(NSString *)vCardString{

NSString *firstname;
NSString *lastname;
NSString *pos;
NSString *company;
NSString *email;
NSString *www;
NSString *tel;
NSString *twitterUserName;
NSString *facebookUserName;

NSArray *myArr = [vCardString componentsSeparatedByString:@"\n"];
for (int i=0; i<[myArr count]; i++) {

    //vorname nachname
    if ([[myArr objectAtIndex:i] rangeOfString:@"FN:"].location != NSNotFound) {

        NSArray *tempArray = [[myArr objectAtIndex:i] componentsSeparatedByString:@":"];
        if ([tempArray count] >= 2) {
            firstname = [[[tempArray objectAtIndex:1]componentsSeparatedByString:@" "] objectAtIndex:0];
            lastname = [[[tempArray objectAtIndex:1]componentsSeparatedByString:@" "] objectAtIndex:1];
        }
    }

    //company
    if ([[myArr objectAtIndex:i] rangeOfString:@"ORG:"].location != NSNotFound) {

        NSArray *tempArray = [[myArr objectAtIndex:i] componentsSeparatedByString:@":"];
        company = [[[tempArray objectAtIndex:1]componentsSeparatedByString:@";"] objectAtIndex:0];
    }

    //title = pos
    if ([[myArr objectAtIndex:i] rangeOfString:@"TITLE:"].location != NSNotFound) {

        NSArray *tempArray = [[myArr objectAtIndex:i] componentsSeparatedByString:@":"];
        pos = [tempArray objectAtIndex:1];
    }

    //email
    if ([[myArr objectAtIndex:i] rangeOfString:@"EMAIL;"].location != NSNotFound) {

        NSArray *tempArray = [[myArr objectAtIndex:i] componentsSeparatedByString:@";"];
        email = [[[tempArray objectAtIndex:2]componentsSeparatedByString:@":"] objectAtIndex:1];
    }


    //tel
    if ([[myArr objectAtIndex:i] rangeOfString:@"VOICE;"].location != NSNotFound) {

        NSArray *tempArray = [[myArr objectAtIndex:i] componentsSeparatedByString:@";"];
        tel = [[[tempArray objectAtIndex:4]componentsSeparatedByString:@":"] objectAtIndex:1];
    }


    //www
    if ([[myArr objectAtIndex:i] rangeOfString:@"URL;"].location != NSNotFound) {

        NSArray *tempArray = [[myArr objectAtIndex:i] componentsSeparatedByString:@";"];
        www = [[[tempArray objectAtIndex:1]componentsSeparatedByString:@":"] objectAtIndex:1];
    }



    //twitter
    if ([[myArr objectAtIndex:i] rangeOfString:@"twitter"].location != NSNotFound) {

        NSArray *tempArray = [[myArr objectAtIndex:i] componentsSeparatedByString:@";"];

        if ([[tempArray objectAtIndex:1] rangeOfString:@"type=twitter"].location != NSNotFound) {

            twitterUserName = [[[[[tempArray objectAtIndex:2]componentsSeparatedByString:@"="] objectAtIndex:1] componentsSeparatedByString:@":"] objectAtIndex:0];

        }

    }

    if ([[myArr objectAtIndex:i] rangeOfString:@"facebook"].location != NSNotFound) {

        NSArray *tempArray = [[myArr objectAtIndex:i] componentsSeparatedByString:@";"];

        if ([[tempArray objectAtIndex:1] rangeOfString:@"type=facebook"].location != NSNotFound) {

            facebookUserName = [[[[[tempArray objectAtIndex:2]componentsSeparatedByString:@"="] objectAtIndex:1] componentsSeparatedByString:@":"] objectAtIndex:0];

        }

    }
}
return [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:firstname,lastname,pos,company,email,www,tel,twitterUserName,facebookUserName, nil] forKeys:[NSArray arrayWithObjects:@"firstname",@"lastname",@"pos",@"company",@"email",@"www",@"tel",@"twitterUserName",@"facebookUserName", nil]];

}

have fun with it.

kurtanamo
  • 1,808
  • 22
  • 27