0

やってみるとCFArrayGetValueAtIndexでソーシャルプロフィール情報(twitter, facebook)を取得できません。名前、番号、wwwなどの他のすべての情報を取得しています。ABPersonCreateVCardRepresentationWithPeople で vCard を作成しました。出力を試してみると、次のような情報が得られます。

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

情報を取り戻そうとしたコードは次のとおりです。

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

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

...人は社会的情報を持っていません。後でソーシャル情報を追加しようとしましたが、これも間違いです。新しい ABPersonCreate() を作成した場合にのみ機能します...それは私の間違いですか? それともまだうまくいきませんか?何か案は?

4

1 に答える 1

0

これは SDK のバグになります...したがって、できることは、文字列を分離して新しい ABPerson を作成することだけです - ABPersonCreate() を使用して - 私のコードを見てください。

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

}

それを楽しんでください。

于 2013-01-31T12:43:22.290 に答える