Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

saurabhcoder

macrumors newbie
Original poster
Apr 11, 2014
1
0
I have an small app which is accessing contacts from iphone 4 but it is not working in iphone 5 with ios 7.1 on both device
below is the code
Code:
- (void)viewDidLoad

{
UIBarButtonItem * barButtonItemTwo = [[UIBarButtonItem alloc]initWithCustomView:btnBack];

    ABAddressBookRef addressBook = ABAddressBookCreate();



    CFErrorRef myError = NULL;



    ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, &myError);

switch (ABAddressBookGetAuthorizationStatus()) {

        case kABAuthorizationStatusNotDetermined: {

            NSLog(@"kABAuthorizationStatusNotDetermined");

            ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {

                // First time access.

                AddressBookUpdated(addressBookRef, nil, (__bridge void *)(self));

                CFRelease(addressBookRef); void insert();

            }); }

            break;

        case kABAuthorizationStatusRestricted:{

            NSLog(@"kABAuthorizationStatusRestricted");

        }

            break;

        case kABAuthorizationStatusDenied:

            NSLog(@"kABAuthorizationStatusDenied");

            break;

        case kABAuthorizationStatusAuthorized:{

            NSLog(@"kABAuthorizationStatusAuthorized");

            AddressBookUpdated(addressBookRef, nil, (__bridge void *)(self));

            CFRelease(addressBookRef);

            break;

        }}

the function by which i the contacts are getting accessed is

Code:
void AddressBookUpdated(ABAddressBookRef addressBook, CFDictionaryRef info, void *context) {



    @try{

    NSString *userDefKey;

    NSString *docsDir;

    NSArray *dirPaths;

    const char *dbpath;

    NSString *databasePath;

    sqlite3 *contactDB;

    sqlite3  *db;

    NSString *dbPath1;

    NSString *dbPath;



   NSMutableArray *data,*number,*email;

   data=[[NSMutableArray alloc]init];

   number=[[NSMutableArray alloc]init];

    email=[[NSMutableArray alloc]init];



    ABAddressBookRevert(addressBook);

    CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);

    CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);



    ABAddressBookRef addressBook1 = ABAddressBookCreate();

    NSArray *people1 = (__bridge NSArray*)ABAddressBookCopyArrayOfAllPeople(addressBook);





    for ( int i = 0; i < nPeople; i++ )

    {

        ABRecordRef person = CFArrayGetValueAtIndex( allPeople, i );

        NSString *firstName = (__bridge NSString *)(ABRecordCopyValue(person, kABPersonFirstNameProperty));

        NSString *lastName = (__bridge NSString *)(ABRecordCopyValue(person, kABPersonLastNameProperty));

        NSString *emailid;

        ABMultiValueRef emailProperty = ABRecordCopyValue(person, kABPersonEmailProperty);

       // ABMultiValueRef multi = ABRecordCopyValue((__bridge ABRecordRef)(person), kABPersonPhoneProperty);

        //NSString *eid=(__bridge NSString *)(ABRecordCopyValue(person, kABPersonEmailProperty));

        NSArray *emailArray = (__bridge NSArray *)ABMultiValueCopyArrayOfAllValues(emailProperty);

       // NSInteger *i=(__bridge NSInteger*)ABRecordCopyValue(person, kABPersonPhoneMobileLabel);



        if(emailArray.count==0)

            [email addObject:@" "];

        else{

        emailid=emailArray[0];

        if(emailid.length!=0)

        [email addObject:emailid];

        }

            //NSLog(@"email array %@",eid);



        if(lastName.length<1)

        {

            [data addObject:firstName];



        }

        else

        {

            NSString *combined = [NSString stringWithFormat: @"%@ %@",

                                  firstName, lastName];

            [data addObject:combined];

        }





        }

    //NSLog(@"phone count is %d",data.count);

   //number = [NSMutableArray arrayWithCapacity:data.count];

    //NSLog(@"phone count is %d",number.count);

    for(id person in people1){

        //fetch multiple phone nos.

        ABMultiValueRef multi = ABRecordCopyValue((__bridge ABRecordRef)(person), kABPersonPhoneProperty);

        for (CFIndex j=0; j < ABMultiValueGetCount(multi); j++) {

            NSString* phone = (__bridge NSString*)ABMultiValueCopyValueAtIndex(multi, j);

            //NSLog(@"phone no is %@",phone);

            [number addObject:phone];



        }

    }
}

i this function i am just accesing the contacts & adding them in array
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.