iOS 8.0 or above
AddressBookKit is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "AddressBookKit"or
Copy AddressBookKit.swift and AddressBookDataType.swift into your project.
Ask for Contacts permission
AddressBookKit.requestPermission { [weak self] (success) -> Void in
if success {
// Success, read address book here...
// Example:
let phoneNumbers = AddressBookKit.plainContacts(.PhoneNumber)
} else {
// No Permission
}
}AddressBookKit.plainContacts() will returns an array of PlainContact. Example:
let phoneNumbers = AddressBookKit.plainContacts(.PhoneNumber)
let emails = AddressBookKit.plainContacts(.Email)AddressBookKit.groupedContacts() will returns an array of GroupedContact. Example:
let phoneNumbers = AddressBookKit.groupedContacts([.PhoneNumber])
let emails = AddressBookKit.groupedContacts([.Email])
let phonesAndEmails = AddressBookKit.groupedContacts([.PhoneNumber, .Email])| Varible | Type | Description |
|---|---|---|
| firstName | String? | First Name |
| middleName | String? | Middle Name |
| lastName | String? | Last Name |
| fullName | String | Full Name |
| value | String | A String representing phone number or email |
| Varible | Type | Description |
|---|---|---|
| firstName | String? | First Name |
| middleName | String? | Middle Name |
| lastName | String? | Last Name |
| fullName | String | Full Name |
| phoneNumbers | [String] | An array of phone numbers in this contact |
| emails | [String] | An array of Emails in this contact |
Kenneth Tsang, kenneth.tsang@me.com
AddressBookKit is available under the MIT license. See the LICENSE file for more info.