2011-01-17 3 views
0

Ich habe Probleme, Telefonnummern aus dem iPhone-Adressbuch zu erhalten.Adressbuch Telefonnummer (+45) Präfix verursacht Absturz!

Es gibt kein Problem, wenn die Zahl enthalten keine Landesvorwahl wie 45, aber wenn es der Fall ist, meine app stürzt ab ...

Ist das ein bekanntes Problem? Ich habe nicht in der Lage, etwas dagegen zu finden ...

Dank

EDIT:

ich Telefonnummer wie folgt aus:

-(void)getContact 
    { 

     ABPeoplePickerNavigationController *pp = [[ABPeoplePickerNavigationController alloc] init]; 
     pp.displayedProperties = [NSArray arrayWithObject:[NSNumber numberWithInt:kABPersonPhoneProperty]]; 
     pp.peoplePickerDelegate = self; 
     [self presentModalViewController:pp animated:YES]; 
     [pp release]; 


    } 

    - (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker { 
     // assigning control back to the main controller 
     [self dismissModalViewControllerAnimated:YES]; 
    } 

    - (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person { 
     return YES; 
    } 

-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier { 

      ABMultiValueRef phoneProperty = ABRecordCopyValue(person,property); 
      saveString = (NSString *)ABMultiValueCopyValueAtIndex(phoneProperty,identifier); 
      saveString = [saveString stringByReplacingOccurrencesOfString:@" " withString:@""]; 
      nummerTextField.text = saveString; 
     } 
+1

Können Sie Ihren Code posten? Und wo kommt der Unfall zustande? –

+0

Vielleicht mag jemand bei Apple das Dänische;) Scheint allerdings etwas unwahrscheinlich. – spender

+0

:-) Der Absturz geschieht bei saveString = (NSString *) ABMultiValueCopyValueAtIndex (phoneProperty, identifier); aber nur wenn die Nummer ein Präfix hat wie +45 ... – CCDEV

Antwort

0

Wie abrufen Sie Ihr Adressbuch Objekt , und sobald es abgerufen wird, wie verarbeiten Sie es, um die Nummer von ihm zu holen. Ich verwende den unten gezeigten Code, um dasselbe zu tun, was Sie erwähnt haben, und es holt die Zahlen genau.

ABRecordRef person = ABAddressBookGetPersonWithRecordID(appDelegate.addressBook, contactId); 

ABMultiValueRef multiValue = ABRecordCopyValue(person, kABPersonPhoneProperty); 

NSArray *allNumbers = (NSArray *)ABMultiValueCopyArrayOfAllValues(multiValue); 
NSMutableDictionary *filteredNumbers = [NSMutableDictionary new]; 

if([allNumbers count] > 0) { 
    for(int contactIndex = 0; contactIndex < [allNumbers count]; contactIndex++) { 
     NSString *contactValue = (NSString *)ABMultiValueCopyLabelAtIndex(multiValue, contactIndex); 
     if(!([contactValue isEqualToString:@"_$!<WorkFAX>!$_"] || [contactValue isEqualToString:@"_$!<HomeFAX>!$_"] || [contactValue isEqualToString:@"_$!<Pager>!$_"])) { 

      if([[contactValue substringWithRange:contactLabelCharacterCustom] isEqualToString:@"_$"]) 
       typeOfContact = [contactValue substringWithRange:contactLabelCharacter]; 
      else 
       typeOfContact = [contactValue substringWithRange:(NSRange){0,1}]; 
      NSString *value = (NSString *)ABMultiValueCopyValueAtIndex(multiValue, contactIndex); 
      [filteredNumbers setValue:typeOfContact forKey:value]; 
      [value release]; 
      value = nil; 
     } 
     [contactValue release]; 
     contactValue = nil; 
    } 
} 

Ich bin sicher, es wird Ihnen helfen.

Prost

+0

Probieren Sie meinen Code, es wird auf jeden Fall funktionieren – Aditya

+0

Probieren Sie es einfach aus ... Ich greife auf die Zahlen durch den Benutzer Auswahl Hexe Nummer/E-Mail ect. er/sie will. Konnte dein Beispiel nicht zur Arbeit bringen :(Vielleicht werde ich es später noch einmal versuchen, wenn alles andere fehlschlägt;) – CCDEV

+0

Prost auf diesen Kumpel! – Aditya

0

Das löste mein Problem. Hoffe jemand findet es hilfreich.

ABMultiValueRef multiValue = ABRecordCopyValue(person, property); 

     NSString *number = (NSString *)ABMultiValueCopyValueAtIndex(multiValue, ABMultiValueGetIndexForIdentifier(multiValue, identifier)); 

// Error was here: NSString *value = (NSString *)ABMultiValueCopyValueAtIndex(multiValue, contactIndex); 

     //Copy the number etc before cleaning everything up 

     saveString = number; 
     saveString = [saveString stringByReplacingOccurrencesOfString:@" " withString:@""]; 
     nummerTextField.text = saveString; 

     [number release]; 
     CFRelease(multiValue); 
Verwandte Themen