Addressbookmanager

Swift Wrapper Class For Apple's ABAddressBook Framework
Alternatives To Addressbookmanager
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Awesome Swift Playgrounds4,009
19 days ago1otherSwift
A List of Awesome Swift Playgrounds
Hellosilicon2,859
a month ago9mitAssembly
An introduction to ARM64 assembly on Apple Silicon Macs
Swift Summary1,668
2 years ago3mitSwift
A summary of Apple's Swift language written on Playgrounds
Learn Swift774
3 years ago14Swift
Learn Apple's Swift programming language interactively through these playgrounds.
Practical Python And Opencv75
6 years agoTeX
:green_apple:Latex: translate the book practical python and opencv to Chinese
Learning Core Audio Swift Samplecode72
3 years ago1mitSwift
Swift sample code for the book, Learning Core Audio. The original sample code was written in C/Objective-C but I tried to make it in Swift version.
Best23
5 years ago1
Gifts for Programmers
Asleye20
55 years ago4October 22, 20181mitSwift
ASLEye is an ASL(Apple System Log) monitor, automatic catch the log from NSLog by asl module
Spritekitbook Swift16
7 years ago6apache-2.0Swift
Source code and resources for the book "Epic SpriteKit Tutorial with Swift"
Middlemac11
2 years ago1mitRuby
Make multi-feature, multi-target macOS Help Books for macOS applications
Alternatives To Addressbookmanager
Select To Compare


Alternative Project Comparisons
Readme

AddressBookManager

CI Status Version License Platform

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Create Instance Of AddressBookManager
import AddressBookManager
...

var abManager: AddressBookManager? = AddressBookManager()
Authorization Status
switch (AddressBookManager.getAuthorizationStatus()) {
    case .Authorized:
        // Authorized To Use AddressBook
    case .Denied:
        // Denied Access To AddressBook
    case .Restricted:
        // Restricted Access To AddressBook
    case .Unknown:
        // Access To AddressBook Unknown, Most Likely AddressBook Authorization Has Not Been Requested Yet
}
Retrieving Contacts
// Option 1
abManager?.requestAuthorizationWithCompletion({ (granted: Bool, error: CFError?) -> Void in
            if (error) {
              // Handle Error 
            } else if (granted) {
              var people = abManager?.allContacts
              // Do Something With Contacts
            }
        })
        
// Option 2 - If you want to use a specific queue for retrieval
abManager?.retrieveAllContactsInQueue(dispatch_get_main_queue(),
            completion: { (contacts: [AddressBookPerson]?, error: CFError?) -> Void in
                if (error) {
                  // Handle Error
                } else {
                  // Do Something With Contacts
                }
        })
Sorting Contacts
// Sort Contacts In Ascending Order By First Name
abManager?.retrieveAllContactsInQueue(dispatch_get_main_queue(),
            sort: { $0.firstName < $1.firstName },
            completion: { (contacts: [AddressBookPerson]?, error: CFError?) -> Void in
                if (error) {
                  // Handle Error
                } else {
                  // Do Something With Contacts
                }
        })
Filtering Contacts
// Retrieve Contacts That Have Atleast One Email
abManager?.retrieveAllContactsInQueue(dispatch_get_main_queue(),
            filter: { count($0.emails!) > 0 },
            completion: { (contacts: [AddressBookPerson]?, error: CFError?) -> Void in
                if (error) {
                  // Handle Error
                } else {
                  // Do Something With Contacts
                }
        })
Sorting And Filtering Contacts
// Retrieve Only Contacts That Have Atleast One Email And Sort Those Contacts In Ascending Order By First Name
abManager?.retrieveAllContactsInQueue(dispatch_get_main_queue(),
            sort: { $0.firstName < $1.firstName },
            filter: { count($0.emails!) > 0 },
            completion: { (contacts: [AddressBookPerson]?, error: CFError?) -> Void in
                if (error) {
                  // Handle Error
                } else {
                  // Do Something With Contacts
                }
        })
Adding Contacts
abm.requestAuthorizationWithCompletion { (granted: Bool, error: CFError?) -> Void in
    var person = AddressBookPerson()
    person.firstName = "Bob"
    person.lastName = "Smith"
            
    var personalEmail = MultiValue(key: "personal", value: "[email protected]")
    person.emails = [personalEmail]
            
    var homePhoneNumber = MultiValue(key: "home", value: "5555555555")
    var mobilePhoneNumber = MultiValue(key: "mobile", value: "1234567890")
    person.phoneNumbers = [homePhoneNumber, mobilePhoneNumber]
            
    person.profilePicture = UIImage(named: "bob.png")
            
    var homeAddress = Dictionary<AddressProperty, AnyObject>()
    homeAddress[AddressProperty.Street] = "123 Maple Street"
    homeAddress[AddressProperty.City] = "Miami"
    homeAddress[AddressProperty.State] = "FL"
    homeAddress[AddressProperty.ZipCode] = "00000"
    homeAddress[AddressProperty.Country] = "USA"
            
    var homeAddressValue = MultiValue(key: "home", value: homeAddress)
    person.addresses = [homeAddressValue]
            
    var dateFormatter: NSDateFormatter = NSDateFormatter()
    dateFormatter.dateFormat = "MM/dd/yyyy"
    let birthday: NSDate? = dateFormatter.dateFromString("01/01/1970")
    person.birthday = birthday
            
    person.organization = "Some Huge Organization"
    person.jobTitle = "Developer"
    person.department = "Software"
    person.note = "Some Note Here"
            
    var personalURL = MultiValue(key: "personal", value: "https://somewebsite")
    person.urls = [personalURL]
            
    person.prefix = "Mr"
    person.suffix = "Jr"
    person.middleName = "Roger"
            
    var anniversaryDate = MultiValue(key: "anniversary", value: dateFormatter.dateFromString("02/02/2000"))
    person.dates = [anniversaryDate]
            
    abm?.addRecord(person)
    abm?.save()
}

Contact-Screenshot

Miscellaneous Methods
  • personCount - returns number of contacts in the address book
  • groupCount - returns number of groups in the address book
  • removeRecord - removes the record (AddressBookRecord) from the address book
  • hasUnsavedChanges - if there were any changes to the address book (additions, removal, etc...) that have not yet been saved

Installation

AddressBookManager is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "AddressBookManager"

OR

You can simply clone this repository and drag the files into your project.

Author

Aadesh Patel, [email protected]

License

AddressBookManager is available under the MIT license. See the LICENSE file for more info.

Popular Apple Projects
Popular Book Projects
Popular Companies Categories

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Swift
Book
Address
Apple
Contacts
Filtering