我想将通讯录中的联系人存储在NSDictionary中。
我成功登录了联系人的名字+姓氏并将其存储在NSDictionary的“名称”中。但是当笑脸或诸如“é”或“è”之类的重音作为名字或姓氏时,会给我这样的错误:"Name = "Manon \Ud83d\Udc9c (null)";"
第二个错误:当联系人有多个电话号码时,该电话号码将其存储在我的NSDictionary“电话号码”中,但给我这样的错误"Number = "06\U00a067\U00a054\U00a069\U00a034";"
也许只用某种方式搜索移动电话号码(以“ 06”或“ +336”开头法国)?并将其添加到NSDictionary的“数字”中?
我该如何解决?
这是我在ViewDidLoad中的代码:
//ADDRESS BOOK
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
if (addressBook != NULL) {
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
if (granted)
{
NSArray *arrayOfPeople = (__bridge_transfer NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
//The array in which the first names will be stored as NSStrings
// self.allContact = [[NSMutableArray alloc] init];
for(NSUInteger index = 0; index <= ([arrayOfPeople count]-1); index++){
ABRecordRef person = (__bridge ABRecordRef)[arrayOfPeople objectAtIndex:index];
NSString *currentFirstName = (__bridge_transfer NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString *currentLastName = (__bridge_transfer NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
NSString *allName = [NSString stringWithFormat:@"%@ %@", currentFirstName, currentLastName];
[self.allContact addObject: allName];
self.contact = [NSMutableDictionary
dictionaryWithDictionary:@{
@"Name" : @"Number"
}];
[self.contact setObject:allName forKey:@"Name"];
ABMultiValueRef phones = ABRecordCopyValue(person, kABPersonPhoneProperty);
if (phones != NULL)
{
for (NSInteger index = 0; index < ABMultiValueGetCount(phones); index++)
{
NSString *phone = CFBridgingRelease(ABMultiValueCopyValueAtIndex(phones, index));
[self.contact setObject:phone forKey:@"Number"];
}
}
NSLog(@"%@", self.contact);
}
//OPTIONAL: The following line sorts the first names alphabetically
NSArray *sortedFirstNames = [self.allContact sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
// NSLog(@"%@", sortedFirstNames);
}
});
}
最佳答案
“名称=” Manon \ Ud83d \ Udc9c(空)“;”
“编号=” 06 \ U00a067 \ U00a054 \ U00a069 \ U00a034“
这不是错误。 \U00a067
和其他都是unicode符号。控制台只是不知道如何显示此类符号(“é”或“è”),这就是为什么它显示unicode符号的原因。
但是,在应用程序中,这些符号将按预期显示。
我一直都用俄语字符表现相同的行为。
关于ios - 带有é,è…和多个数字的通讯簿名称,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31687052/