简体   繁体   中英

How to take permission of contact access in iOS5?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM