Code Monkey home page Code Monkey logo

contactmanager's Introduction

ContactManager

BuddyBuild Version License Platform

A Swift library for Contacts framework.

Requirements

  • iOS 9.0+

Example

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

Installation

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

pod "ContactManager"

Get started

Import SwiftyContacts into your porject

import SwiftyContacts

For requesting an access for getting contacts. The user will only be prompted the first time access is requested.

requestAccess { (responce) in
if responce{
print("Contacts Acess Granted")
} else {
print("Contacts Acess Denied")
}
}

Determine Status of Acess Permission

authorizationStatus { (status) in
switch status {
case .authorized:
print("authorized")
break
case .denied:
print("denied")
break
default:
break
}
}

Fetch Contacts -- Result will be Array of CNContacts

fetchContacts(completionHandler: { (result) in
switch result{
case .Success(response: let contacts):
// Do your thing here with [CNContacts] array	 
break
case .Error(error: let error):
print(error)
break
}
})

Fetch Contacts on Background Thread

fetchContactsOnBackgroundThread(completionHandler: { (result) in
switch result{
case .Success(response: let contacts):
// Do your thing here with [CNContacts] array	 
break
case .Error(error: let error):
print(error)
break
}
})

Search Contact

searchContact(SearchString: "john") { (result) in
switch result{
case .Success(response: let contacts):
// Contacts Array includes Search Result Contacts
break
case .Error(error: let error):
print(error)
break
}
}

Get CNContact From Identifire

getContactFromID(Identifire: "XXXXXXXXX", completionHandler: { (result) in  
switch result{
case .Success(response: let contact):
// CNContact
break
case .Error(error: let error):
print(error)
break
}
})

Add Contact

let contact : CNMutableContact = CNMutableContact()
contact.givenName = "Satish"
// OR Use contact.mutableCopy() For Any CNContact

addContact(Contact: contact) { (result) in
switch result{
case .Success(response: let bool):
if bool{
print("Contact Sucessfully Added")
}
break
case .Error(error: let error):
print(error.localizedDescription)
break
}
}

Add Contact in Container

addContactInContainer(Contact: CNMutableContact, Container_Identifier: String) { (result) in
//Same As Add Contact
}

Update Contact

updateContact(Contact: contact) { (result) in
switch result{
case .Success(response: let bool):
if bool{
print("Contact Sucessfully Updated")
}
break
case .Error(error: let error):
print(error.localizedDescription)
break
}
}

Delete Contact

// Use contact.mutableCopy() To convert CNContact to CNMutableContact
deleteContact(Contact: contact) { (result) in
switch result{
case .Success(response: let bool):
if bool{
print("Contact Sucessfully Deleted")
}
break
case .Error(error: let error):
print(error.localizedDescription)
break
}
}

Fetch List Of Groups

fetchGroups { (result) in
switch result{
case .Success(response: let groups):
// List Of Groups in groups array
break
case .Error(error: let error):
print(error.localizedDescription)
break
}
}

Create Group

createGroup(Group_Name: "Satish") { (result) in
switch result{
case .Success(response: let bool):
if bool{
print("Group Sucessfully Created")
}
break
case .Error(error: let error):
print(error.localizedDescription)
break
}
}

Create Group in Container

createGroup(Group_Name: "Satish" , ContainerIdentifire: "ID") { (result) in
switch result{
case .Success(response: let bool):
if bool{
print("Group Sucessfully Created")
}
break
case .Error(error: let error):
print(error.localizedDescription)
break
}
}

Update Group

updateGroup(Group: group, New_Group_Name: "New Name") { (result) in
switch result{
case .Success(response: let bool):
if bool{
print("Group Sucessfully Updated")
}
break
case .Error(error: let error):
print(error.localizedDescription)
break
}
}

Remove Group

removeGroup(Group: group) { (result) in
switch result{
case .Success(response: let bool):
if bool{
print("Group Sucessfully Removed")
}
break
case .Error(error: let error):
print(error.localizedDescription)
break
}
}

Fetch Contacts In Group

fetchContactsInGorup(Group: group) { (result) in
switch result{
case .Success(response: let contacts):
// Do your thing here with [CNContacts] array	 
break
case .Error(error: let error):
print(error)
break
}
}

// OR Use

fetchContactsInGorup2(Group: group) { (result) in
switch result{
case .Success(response: let contacts):
// Do your thing here with [CNContacts] array	 
break
case .Error(error: let error):
print(error)
break
}
}

Add Contact To Group

addContactToGroup(Group: group, Contact: contact) { (result) in
switch result{
case .Success(response: let bool):
if bool{
print("Contact Sucessfully Added To Group")         
}
break
case .Error(error: let error):
print(error.localizedDescription)
break
}
}

Remove Contact From Group

removeContactFromGroup(Group: group, Contact: contact) { (result) in
switch result{
case .Success(response: let bool):
if bool{
print("Contact Sucessfully Added To Group")
}
break
case .Error(error: let error):
print(error.localizedDescription)
break
}
}

Convert [CNContacts] TO CSV

contactsToVCardConverter(contacts: ContactsArray) { (result) in
switch result {
case .Success(response: data):
// Use file extension will be .vcf
break
case .Error(error: let error):
print(error.localizedDescription)
break

}
}

Convert CSV TO [CNContact]

VCardToContactConverter(data: data) { (result) in
switch result{
case .Success(response: let contacts):
// Use Contacts array as you like   
break
case .Error(error: let error):
print(error.localizedDescription)
break
}
}

Find Duplicates Contacts

findDuplicateContacts(Contacts: contactsArray) { (duplicatesContacts) in
//Duplicates Contacts Array 
//Array type [Array<CNContact>]
}

Author

Viraj Patel, [email protected]

License

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.