地址簿名称带有é,è...和多个数字

时间:2015-07-28 21:04:30

标签: ios objective-c nsdictionary addressbook abaddressbook

我想在 NSDictionary 中存储地址簿的联系方式。

我成功记录名字+联系的姓氏并存储在 NSDictionary “name”中。但当笑脸或某些口音如“é”或“è”出现在名字或姓氏时,会给我这样的错误:"Name = "Manon \Ud83d\Udc9c (null)";"

第二个错误:当联系人有多个号码时,会将号码存储在我的 NSDictionary “号码”中,但会给我这样的错误"Number = "06\U00a067\U00a054\U00a069\U00a034";"也许只能用于搜索MOBILE号码(在法国以“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);


        }
    });
}

1 个答案:

答案 0 :(得分:1)

  

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

这不是错误。 \U00a067和其他人是unicode符号。控制台只是不知道如何显示这些符号(“é”或“è”),这就是它显示unicode符号的原因。 但是在应用中,这些符号将按预期显示 我一直对俄语字符有同样的行为。