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

发布于 2024-12-18 11:18:42 字数 1471 浏览 3 评论 0原文

我只能将陈列室名称添加到我的联系人中。但是当我输入代码来添加电话号码、更多详细信息时......我的代码崩溃了。任何建议将不胜感激。这是我的代码

- (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).

I am able to add only showroom name to my contacts. But when I put the code to add phone numbers, further details....my code get crash. Any suggestion would be appreciated. Here is my code

- (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);

Shows following message

[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).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

十年九夏 2024-12-25 11:18:42

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

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);

    }

如有任何疑问,请询问...很乐意提供帮助

If you want only to improve your code. I have checked once your code its fine working just add the following lines

ABAddressBookAddRecord(addressBook,Showroom, nil);


    ABAddressBookSave(addressBook,nil); 

    objABPersonViewController=[[ABUnknownPersonViewController alloc]init];

    objABPersonViewController.displayedPerson=Showroom;

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


    CFRelease(Showroom);

And if you want to use mine check this out. It will also add an image named abc.png from your resource folder to the contact list.

 -(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);

    }

for any further query just ask... Happy to help

皇甫轩 2024-12-25 11:18:42

这是您的问题 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)sender{

    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];

}

This is the Answer to your question Navnath. Apple provides ABNewPersonViewController to open the particular add contact view.Add the ABNewPersonViewControllerDelegate in your header file.

case 1:Application is view based:-

     -(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];
}

case 2:Application is navigation based:-

-(IBAction)displayContactAddWindow:(id)sender{

    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];

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文