这将是 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]];
}
玩得开心。