iOS Phone book Import code

Source: Internet
Author: User

iOS phone book import code, currently only implement the main box program, details renewal; analysis does not cause a memory leak

Reference

#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>

Code debugging: xcode4.5,ios6.0

Body Code

- (void) testaddress{abaddressbookref addressbook=Nil; if([[Uidevice currentdevice].systemversion Floatvalue] >=6.0) {AddressBook=abaddressbookcreatewithoptions (null, NULL); //wait for consent and then execute downdispatch_semaphore_t sema = Dispatch_semaphore_create (0); Abaddressbookrequestaccesswithcompletion (AddressBook,^(BOOLgranted, cferrorref error)                                                 {dispatch_semaphore_signal (SEMA);        });        Dispatch_semaphore_wait (Sema, dispatch_time_forever);    Dispatch_release (SEMA); }//Else//    {//addressbook = Abaddressbookcreate ();//    }cfarrayref Results=abaddressbookcopyarrayofallpeople (AddressBook); NSLog (@"%@", results); intPeoplecount =Cfarraygetcount (results);  for(intI=0; i<peoplecount; i++) {Abrecordref record=Cfarraygetvalueatindex (results, i); NSLog (@"%@", record); NSString*fn,*ln,*fullname; FN= LN = FullName =Nil; Cftyperef vtmp=NULL; Vtmp=Abrecordcopyvalue (record, kabpersonfirstnameproperty); if(vtmp) {fn=[NSString stringwithstring:vtmp];            Cfrelease (VTMP); Vtmp=NULL; } vtmp=Abrecordcopyvalue (record, kabpersonlastnameproperty); if(vtmp) {ln=[NSString stringwithstring:vtmp];            Cfrelease (VTMP); Vtmp=NULL; } NSLog (@"%@ ,%@", FN, LN); //Read PhoneAbmultivalueref phones =Abrecordcopyvalue (record, kabpersonphoneproperty); intPhonecount =abmultivaluegetcount (phones);  for(intj=0; j<phonecount; J + +)        {            //labelCfstringref lable =Abmultivaluecopylabelatindex (phones, j); //Phone numberCfstringref PhoneNumber =Abmultivaluecopyvalueatindex (phones, j); //Localize LabelCfstringref LL =Abaddressbookcopylocalizedlabel (lable); NSLog (@"\t%@,%@,%@", (NSString *) lable, (NSString *) ll, (NSString *) PhoneNumber); if(LL) cfrelease (LL); if(lable) cfrelease (lable); if(PhoneNumber) cfrelease (PhoneNumber); }                if(phones) cfrelease (phones); Record=NULL; }        if(Results) cfrelease (results); Results=Nil; if(AddressBook) cfrelease (addressbook); AddressBook=NULL;}

Go to: http://www.cnblogs.com/GoGoagg/archive/2012/12/20/2826804.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.