ios - 带有 é,è ... 和多个号码的地址簿名称

标签 ios objective-c nsdictionary addressbook abaddressbook

我想在 NSDictionary 中存储来自Address Book 的联系人。

我成功地记录联系人的名字+姓氏并存储在NSDictionary“名称”中。但是,当名字或姓氏中出现笑脸符号或类似“é”或“è”的重音时,就会出现这样的错误:"Name = "Manon\Ud83d\Udc9c (null)";"

第二个错误:当联系人有多个号码时,将号码存储在我的 NSDictionary“号码”中,但给我这样的错误 "Number = "06\U00a067\U00a054\U00a069\U00a034";" 也许只使用搜索手机号码的东西(在法国以“06”或“+336”开头)?并将其添加到 NSDictionary “number” ?

如何修复它?

这是我在 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);


        }
    });
}

最佳答案

"Name = "Manon \Ud83d\Udc9c (null)";"
"Number = "06\U00a067\U00a054\U00a069\U00a034"

这不是一个错误。 \U00a067 等都是unicode符号。控制台只是不知道如何显示此类符号(“é”或“è”),这就是它显示 unicode 符号的原因。 然而在应用程序中,这些符号将按预期显示。
我一直对俄语角色有同样的行为。

关于ios - 带有 é,è ... 和多个号码的地址簿名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31687052/

相关文章:

objective-c - 将字符串 ("MyExampleClass") 转换为类名 (MyExampleClass)

ios - 我从哪里开始在 main.m 第 15 行中寻找 SIGSEGV 的原因

ios - .pch 文件中的#define 不起作用

ios - NSMutableDictionary 和 CFDictionaryRef 有什么区别?

ios - 从另一个 NSDictionary 获取 NSArray,其中包含原始键集的子集

html - Swift - multipart/form-data - 如何定义边界/填充 HTML 正文?

iphone - 要求用户通过 iphone 中的 exit(0) 重新启动应用程序?

关闭时的 iOS presentViewController 动画

ios - 按值重新组织字典顺序?

objective-c - 对象-c/iOS :About use NSUserDefaults set serial numbers/password