2011-08-12 9 views
1

私のiPad 2のアドレス帳にアクセスする際に問題が発生しました。特に、連絡先の電子メールを取得する際に問題があります。私がしたいのは、アドレス帳にアクセスし、連絡先を取得してテーブルビューで表示することです。連絡先の名前と姓が表示されているので、すべて正常に動作しているようです。私はそれを取得しようとすると私は "EXC_BAD_ACCESS"を取得するので、問題は、電子メールのプロパティです。 私はテーブルビューのレコードを表示するために書いたコードは以下の通りです:ABMultiValueRefのiOSアドレス帳エラー

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    static NSString *tableIdentifier = @"tableIdentifier"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableIdentifier]; 

    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:tableIdentifier] autorelease]; 
    } 

    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    cell.textLabel.backgroundColor = [UIColor clearColor]; 
    cell.detailTextLabel.backgroundColor = [UIColor clearColor]; 

    NSUInteger row = [indexPath row]; 

    NSString *firstName = (NSString *)ABRecordCopyValue([contacts objectAtIndex:row], kABPersonFirstNameProperty); 
    NSString *lastName = (NSString *)ABRecordCopyValue([contacts objectAtIndex:row], kABPersonLastNameProperty); 
    NSString *name = [[NSString alloc] initWithFormat:@"%@ %@", lastName,firstName]; 

    [firstName release]; 
    [lastName release]; 

    cell.textLabel.text = name; 

    [name release]; 

    NSArray *emails = [[self getEmailForPerson:row] retain]; 

    /*......*/ 

    return cell; 
} 

機能は私の連絡先の電子メールを取得する一方で、次のとおりです。

- (NSArray *)getEmailForPerson:(NSInteger)index{ 
    //Create the array where emails will be stored 
    NSMutableArray *m = [[[NSMutableArray alloc] init] autorelease]; 
    //Get the email properties 
    ABMultiValueRef mails = ABRecordCopyValue([self.contacts objectAtIndex:index], kABPersonEmailProperty); 
    //Iterate in the multi-value properties 
    for (int i=0; i<ABMultiValueGetCount(mails); i++) { 
     //Get the email 
     NSString *mail = (NSString *) ABMultiValueCopyValueAtIndex(mails, i); 
     //Add the email to the array previously initializated 
     [m addObject:mail]; 
     [mail release]; 
    } 
    CFRelease(mails); 

    return m; 
} 

私はこの文の後にデバッガを実行すると、

ABMultiValueRef mails = ABRecordCopyValue([self.contacts objectAtIndex:index], kABPersonEmailProperty); 

メールアドレスは0x0ですが、私はその理由を理解できません。 誰かが私を助けてくれることを願っています。それは私のアプリでは正常に動作し、事前

+1

私はこの同じ問題を抱えています。理由を発見したことはありますか? – DexterW

答えて

1
ABMultiValueRef mails = ABRecordCopyValue([self.contacts objectAtIndex:index], kABPersonEmailProperty); 

感謝。

チェックフレームワーク& self.contacts。

私のアプリは2つのフレームワークを使用しています。

#import <AddressBook/AddressBook.h> 
#import <AddressBook/ABAddressBook.h> 
関連する問題