satishbabariya / Swiftycontacts
Projects that are alternatives of or similar to Swiftycontacts
SwiftyContacts
This document is deprecated new document is on the way
A Swift library for Contacts framework.
Requirements
- iOS 9.0+ / Mac OS X 10.12+ / watchOS 3.0+
- Xcode 9.0+
Installation
CocoaPods
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapods
To integrate SwiftyContacts into your Xcode project using CocoaPods, specify it in your Podfile
:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
pod 'SwiftyContacts'
#or
pod 'SwiftyContacts/RxSwift'
For swift 3.x use
// Swift 3.x
pod 'SwiftyContacts' , '~> 2.0.7'
Then, run the following command:
$ pod install
Carthage
Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.
You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthage
To integrate SwiftyContacts into your Xcode project using Carthage, specify it in your Cartfile
:
github "SwiftyContacts/SwiftyContacts" ~> 3.0.8
Swift Package Manager
To use SwiftyContacts as a Swift Package Manager package just add the following in your Package.swift file.
import PackageDescription
let package = Package(
name: "HelloSwiftyContacts",
dependencies: [
.Package(url: "https://github.com/satishbabariya/SwiftyContacts", "3.0.8")
]
)
Manually
If you prefer not to use either of the aforementioned dependency managers, you can integrate SwiftyContacts into your project manually.
Embeded Binaries
- Download the latest release from https://github.com/satishbabariya/SwiftyContacts/releases
- Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the "Targets" heading in the sidebar.
- In the tab bar at the top of that window, open the "General" panel.
- Click on the
+
button under the "Embedded Binaries" section. - Add the downloaded
SwiftyContacts.framework
. - And that's it!
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 { (result) in
switch result {
case .success(let contacts):
// Do your thing here with [CNContacts] array
break
case .failure(let error):
break
}
}
Fetch Contacts by Order -- Sorted by CNContactSortOrder -- Result will be Array of CNContacts
fetchContacts(ContactsSortorder: .givenName) { (result) in
switch result{
case .success(let contacts):
// Do your thing here with [CNContacts] array
break
case .failure(let error):
print(error)
break
}
})
Fetch Contacts on Background Thread
fetchContactsOnBackgroundThread(completionHandler: { (result) in
switch result{
case .success(let contacts):
// Do your thing here with [CNContacts] array
break
case .failure(let error):
print(error)
break
}
})
Search Contact
searchContact(SearchString: "john") { (result) in
switch result{
case .success(let contacts):
// Contacts Array includes Search Result Contacts
break
case .failure(let error):
print(error)
break
}
}
Get CNContact From Identifire
getContactFromID(Identifire: "XXXXXXXXX", completionHandler: { (result) in
switch result{
case .success(let contact):
// CNContact
break
case .failure(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(let bool):
if bool{
print("Contact Sucessfully Added")
}
break
case .failure(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(let bool):
if bool{
print("Contact Sucessfully Updated")
}
break
case .failure(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(let bool):
if bool{
print("Contact Sucessfully Deleted")
}
break
case .failure(let error):
print(error.localizedDescription)
break
}
}
Fetch List Of Groups
fetchGroups { (result) in
switch result{
case .success(let groups):
// List Of Groups in groups array
break
case .failure(let error):
print(error.localizedDescription)
break
}
}
Create Group
createGroup(Group_Name: "Satish") { (result) in
switch result{
case .success(let bool):
if bool{
print("Group Sucessfully Created")
}
break
case .failure(let error):
print(error.localizedDescription)
break
}
}
Create Group in Container
createGroup(Group_Name: "Satish" , ContainerIdentifire: "ID") { (result) in
switch result{
case .success(let bool):
if bool{
print("Group Sucessfully Created")
}
break
case .failure(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 .failure(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 .failure(let error):
print(error.localizedDescription)
break
}
}
Fetch Contacts In Group
fetchContactsInGorup(Group: group) { (result) in
switch result{
case .success(let contacts):
// Do your thing here with [CNContacts] array
break
case .failure(let error):
print(error)
break
}
}
// OR Use
fetchContactsInGorup2(Group: group) { (result) in
switch result{
case .success(let contacts):
// Do your thing here with [CNContacts] array
break
case .failure(let error):
print(error)
break
}
}
Add Contact To Group
addContactToGroup(Group: group, Contact: contact) { (result) in
switch result{
case .success(let bool):
if bool{
print("Contact Sucessfully Added To Group")
}
break
case .failure(let error):
print(error.localizedDescription)
break
}
}
Remove Contact From Group
removeContactFromGroup(Group: group, Contact: contact) { (result) in
switch result{
case .success(let bool):
if bool{
print("Contact Sucessfully Added To Group")
}
break
case .failure(let error):
print(error.localizedDescription)
break
}
}
Convert [CNContacts] TO CSV
contactsToVCardConverter(contacts: ContactsArray) { (result) in
switch result {
case .success(let data):
// Use file extension will be .vcf
break
case .failure(let error):
print(error.localizedDescription)
break
}
}
Convert CSV TO [CNContact]
VCardToContactConverter(data: data) { (result) in
switch result{
case .success(let contacts):
// Use Contacts array as you like
break
case .failure(let error):
print(error.localizedDescription)
break
}
}
Author
Satish Babariya, [email protected]
License
SwiftyContacts is available under the MIT license. See the LICENSE file for more info.