代码在添加电话联系人查询时崩溃

时间:2011-11-28 07:25:59

标签: iphone crash addressbook

我只能在我的联系人中添加陈列室名称。但是,当我把代码添加到电话号码,进一步的细节....我的代码崩溃。任何建议将不胜感激。这是我的代码

- (IBAction)AddContact
 {   
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef Showroom = ABPersonCreate();

//adding contact name as showroom name
ABRecordSetValue(Showroom, kABPersonFirstNameProperty, ShowroomName.text , nil);

//adding phone number
ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
 ABMultiValueAddValueAndLabel(multiPhone, p_BcardLabel.text, kABPersonPhoneMainLabel, NULL);

 ABRecordSetValue(Showroom, kABPersonPhoneProperty, multiPhone,nil);
 CFRelease(multiPhone);
//adding emailaddress
 ABMutableMultiValueRef multiEmail =  ABMultiValueCreateMutable(kABMultiStringPropertyType);
 ABMultiValueAddValueAndLabel(multiEmail, email_BcardLabel.text, kABWorkLabel,   NULL);
 ABRecordSetValue(Showroom, kABPersonEmailProperty, multiEmail, @"");
 CFRelease(multiEmail);

 //adding URL
 ABMutableMultiValueRef multiURL = ABMultiValueCreateMutable(kABMultiStringPropertyType);
 ABMultiValueAddValueAndLabel(multiURL, url_BcardLabel.text, kABHomeLabel, NULL);
 ABRecordSetValue(Showroom, kABPersonURLProperty, multiURL, @"");
 CFRelease(multiURL);

显示以下消息

[Switching to thread 11779]
warning: Unable to read symbols for   /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.2   (8H7)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).

2 个答案:

答案 0 :(得分:1)

如果您只想改进代码。我已经检查过你的代码,它的工作正常,只需添加以下行

ABAddressBookAddRecord(addressBook,Showroom, nil);


    ABAddressBookSave(addressBook,nil); 

    objABPersonViewController=[[ABUnknownPersonViewController alloc]init];

    objABPersonViewController.displayedPerson=Showroom;

    [self.navigationController pushViewController:objABPersonViewController animated:YES];


    CFRelease(Showroom);

如果你想用我的,请查看。它还会将资源文件夹中名为abc.png的图像添加到联系人列表中。

 -(IBAction)addToAddressbook:(id)sender{ 
        NSString *fname=@"Person First Name";

        NSString *lname=@"Person Last Name";

        NSArray *arrayAdd=[[NSArray alloc]initWithObjects:@"street Name",@"city Name",@"country code",@"zip",nil];

        UIImage *image=[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"abc.png" ofType:nil]];

        [self addContact:fname:lname:arrayAdd:image];
    }

    -(void) addContact:(NSString *)firstname:(NSString *)lastname:(NSArray *)arrayAddress:(UIImage *)currentImage
    {
        ABAddressBookRef addressBook=ABAddressBookCreate();

        ABRecordRef person=ABPersonCreate();

        //set Image
        NSData * dataRef = UIImagePNGRepresentation(currentImage);

        ABPersonSetImageData(person, (CFDataRef)dataRef, nil);

        //set FirstName and LastName
        ABRecordSetValue(person, kABPersonFirstNameProperty,firstname, nil);

        ABRecordSetValue(person, kABPersonLastNameProperty,lastname, nil);


        //Add Address
        ABMutableMultiValueRef address=ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);

        NSMutableDictionary *addressDictionary=[[NSMutableDictionary alloc]init];

        [addressDictionary setObject:[arrayAddress objectAtIndex:0] forKey:(NSString *)kABPersonAddressStreetKey];

        [addressDictionary setObject:[arrayAddress objectAtIndex:1]forKey:(NSString *)kABPersonAddressCityKey];

        [addressDictionary setObject:[arrayAddress objectAtIndex:2] forKey:(NSString *)kABPersonAddressCountryCodeKey];

        [addressDictionary setObject:[arrayAddress objectAtIndex:3] forKey:(NSString *)kABPersonAddressCountryKey];

        ABMultiValueAddValueAndLabel(address, addressDictionary, kABHomeLabel, nil);

        ABRecordSetValue(person, kABPersonAddressProperty, address, nil);

        ABAddressBookAddRecord(addressBook,person, nil);

        ABAddressBookSave(addressBook,nil); 

        objABPersonViewController=[[ABUnknownPersonViewController alloc]init];

        objABPersonViewController.displayedPerson=person;

        [self.navigationController pushViewController:objABPersonViewController animated:YES];


        CFRelease(person);

    }

对于任何进一步的查询只是问...乐于助人

答案 1 :(得分:0)

这是你的问题Navnath的答案。 Apple提供ABNewPersonViewController来打开特定的添加联系人视图。在头文件中添加ABNewPersonViewControllerDelegate。

案例1:应用程序是基于视图的: -

     -(IBAction)displayContactAddWindow:(id)sender{
    ABNewPersonViewController *picker = [[ABNewPersonViewController alloc] init];
    picker.newPersonViewDelegate = self;

    UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:picker];
    [self presentModalViewController:navigation animated:YES];

    [picker release];
    [navigation release];
}

案例2:应用程序基于导航: -

- (IBAction为)displayContactAddWindow:(ID)发送方{

    ABNewPersonViewController *picker = [[ABNewPersonViewController alloc] init];

    picker.newPersonViewDelegate = self;

    [self.navigationController pushViewController:picker animated:YES];

    [picker release];

   }

- (void)newPersonViewController:(ABNewPersonViewController *)newPersonView didCompleteWithNewPerson:(ABRecordRef)person{

    [self.navigationController popViewControllerAnimated:YES];

}