0

I have developed an app which is fetching contacts from iphone its working fine in iphone 4 but it is failed to do the same in iphone 5 . view did load--------

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

function for fetching contact in this function i am fetching contacts & taking them in an array

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

        }
    }


    NSLog(@"data is %@",data);
    NSLog(@"phone number %@",number);
    NSLog(@"email id is %@",email);
}
BenMorel
  • 34,448
  • 50
  • 182
  • 322
Saurabh Mishra
  • 881
  • 1
  • 8
  • 22
  • 1
    What actually happens with your code? Have you debugged the code to see what is happening? – rmaddy Apr 12 '14 at 04:33
  • @rmaddy actually i have iphone 4 it is working fine in that fetching all contacts but my client is having iphone 5 he is telling me that it is not fetching any contact – Saurabh Mishra Apr 12 '14 at 04:42
  • What version of iOS on the iPhone? Note apps were stealing private data from user's address book so Apple banned some APIs in newer versions of iOS. – Abhi Beckert Apr 12 '14 at 05:02
  • @AbhiBeckert ios 7.1 on both device .If apple has banned this then it should not work on iphone 4 too why only iphone 5 while both are running on ios 7.1 – Saurabh Mishra Apr 12 '14 at 05:06
  • Your `break;` statements are confused. For the first two cases, it is inside the brackets. For the third, there aren't any brackets at all, and the last, it is inside the bracket. Not good practice. – erdekhayser Apr 12 '14 at 17:08
  • What's the `ABAddressBookGetAuthorizationStatus` returned? – Larme Apr 12 '14 at 18:10
  • @Larme ABAdressBookGetAutorizationStatus rutrned on iphone 4 is kABAuthorizationStatusAuthorized & its working fine but cant say anything in case of iphone 5 becoz i dont have that my, client is facing this problem – Saurabh Mishra Apr 14 '14 at 05:26
  • Could you check the log of the status on iPad? (since there is a `NSLog`)? Or provide a little user interface for the beta user with a UIAlertView showing with the status returned? – Larme Apr 14 '14 at 09:19

0 Answers0