0

I am making an application which is compatible with iOS5 and it I want to take permission before to access the user contact list. In iOS6 I am able to do this but in iOS5 I have not found any code for to this. I am using it to access the contact list -

ABAddressBookRef addressBook = ABAddressBookCreate();
    CFArrayRef all = ABAddressBookCopyArrayOfAllPeople(addressBook);
    CFIndex n = ABAddressBookGetPersonCount(addressBook);

    for( int i = 0 ; i < n ; i++ )
    {
        ABRecordRef ref = CFArrayGetValueAtIndex(all, i);
        ABMultiValueRef *phones = ABRecordCopyValue(ref, kABPersonPhoneProperty);
        for(CFIndex j = 0; j < ABMultiValueGetCount(phones); j++)
        {


            CFStringRef phoneNumberRef = ABMultiValueCopyValueAtIndex(phones, j);
            //CFRelease(phones);
            NSString *phoneNumber = (__bridge NSString *)phoneNumberRef;
            CFRelease(phoneNumberRef);
            // NSString *s = @"foo/bar:baz.foo";
            NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"+- *#( )"];
            phoneNumber = [[phoneNumber componentsSeparatedByCharactersInSet: doNotWant] componentsJoinedByString: @""];

            NSLog(@"phone number new %@", phoneNumber);


        }
    }

Please suggest how to do this.

Matt
  • 74,352
  • 26
  • 153
  • 180
saurabh jain
  • 19
  • 2
  • 8
  • 1
    Permissions for contacts was added in iOS 6.0. You don't need (and can't) get permission prior to iOS 6.0. – rmaddy Jan 02 '13 at 05:35

1 Answers1

2

Since the Address Book permission requirement was only recently added as of iOS 6 you don't have to ask for permission.

If you still want to do that then you would simply show an UIAlertView and record the user's choice in NSUserDefaults.

Note though that if the user upgrades from iOS 5 to 6 he would be asked again, so you would have to disable your iOS 5 permission dialog in that case.

Cocoanetics
  • 8,171
  • 2
  • 30
  • 57