Question

Im reading the iPhone Address book and getting strange data that brake the json i'm trying to send to server' the retrieving code is this:

    CFErrorRef * error = NULL;
    ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, error);
    CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
    CFIndex numberOfPeople = ABAddressBookGetPersonCount(addressBook);

    for(int i = 0; i < numberOfPeople; i++)
    {

        ABRecordRef person = CFArrayGetValueAtIndex( allPeople, i );
//        NSString* firstName = (__bridge_transfer NSString*)ABRecordCopyValue(person,kABPersonFirstNameProperty);
        CFStringRef nameF = (CFStringRef)ABRecordCopyValue(person, kABPersonFirstNameProperty);
        NSString* firstName = (__bridge_transfer NSString*)nameF;
        CFStringRef nameL = (CFStringRef)ABRecordCopyValue(person, kABPersonLastNameProperty);
        NSString* lastName = (__bridge_transfer NSString*)nameL;
//        NSString* lastName = (__bridge_transfer NSString*)ABRecordCopyValue(person,kABPersonLastNameProperty);
    //    [lastName UTF8String];
    //    [firstName UTF8String];
        //      NSString* phone = nil;
        ABMultiValueRef phoneNumbers = ABRecordCopyValue(person,kABPersonPhoneProperty);

        if (ABMultiValueGetCount(phoneNumbers) > 0) {
            self.phone = (__bridge_transfer NSString*)
            ABMultiValueCopyValueAtIndex(phoneNumbers, 0);
            ABMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty);
            CFStringRef email = ABMultiValueCopyValueAtIndex(emails, 0);
            theEmail = (__bridge_transfer NSString*)email;
            //                  NSLog(@"theEmail:%@", theEmail);
        }
        else
        {
            self.phone = @"";
        }
        // get all email associated with this person
        ABMultiValueRef emailProperty = ABRecordCopyValue(person, kABPersonEmailProperty) ;
        // convert it to an array
        CFArrayRef allEmails = ABMultiValueCopyArrayOfAllValues(emailProperty) ;
        // add these emails to our initial array
        [emails addObjectsFromArray: (__bridge NSArray *)allEmails] ;
         NSLog(@"phone:%@",self.phone);
         NSLog(@"firstName:%@",firstName);
         NSLog(@"lastName:%@",lastName);

        if (firstName == nil) {
            firstName = @"";
        }
        if (lastName == nil) {
            lastName = @"";
        }
        if (theEmail == nil) {
            theEmail = @"";
        }
        sing.contactsDict = [[NSMutableDictionary alloc]init];

        [sing.contactsDict setObject:firstName forKey:@"fname"];
        [sing.contactsDict setObject:lastName forKey:@"lname"];
        [sing.contactsDict setObject:self.phone forKey:@"phone"];
        [sing.contactsDict setObject:theEmail forKey:@"emails"];
//        NSLog(@"[sing.contactsDict description]--> %@",[sing.contactsDict description]);
        [ContactsList addObject:sing.contactsDict];
    }

when i NSLog it i see some of the contacts first name like this:2013-07-15 19:03:46.964 numbex[2635:907] firstName:קופ\327\241א

2013-07-15 19:03:46.961 numbex[2635:907] lastName:(null)

2013-07-15 19:03:46.962 numbex[2635:907] phone:+972549454456 2013-07-15 19:03:46.964 numbex[2635:907] firstName:קופ\327\241א I tried to replace the "\" with this code:

  NSString *str  = [jsonStringt stringByReplacingOccurrences:@"\\" withString:@" "];

and this:

NSString *str  = [jsonStringt stringByReplacingOccurrencesOfString:@"\\" withString:@"#" options:0 range:NSMakeRange(0, jsonStringt.length)];

but nothing is working can someone help please

Thanks

Was it helpful?

Solution

OK i found a way to solve it: i converted all hebrew chars to hebrew ASCII 1255 code page in in this way: 'א' converted to 'e0' and so on to all chars and the the other way around and now all is working, i think its a work around but its working.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top