|
@@ -11,6 +11,7 @@ import UIKit
|
|
|
|
|
|
class DeviceContactsHandler {
|
|
class DeviceContactsHandler {
|
|
private let store = CNContactStore()
|
|
private let store = CNContactStore()
|
|
|
|
+ weak var contactListDelegate: ContactListDelegate?
|
|
|
|
|
|
private func makeContactString(contacts: [CNContact]) -> String {
|
|
private func makeContactString(contacts: [CNContact]) -> String {
|
|
var contactString: String = ""
|
|
var contactString: String = ""
|
|
@@ -28,6 +29,7 @@ class DeviceContactsHandler {
|
|
let storedContacts = fetchContactsWithEmailFromDevice()
|
|
let storedContacts = fetchContactsWithEmailFromDevice()
|
|
let contactString = makeContactString(contacts: storedContacts)
|
|
let contactString = makeContactString(contacts: storedContacts)
|
|
dc_add_address_book(mailboxPointer, contactString)
|
|
dc_add_address_book(mailboxPointer, contactString)
|
|
|
|
+ contactListDelegate?.deviceContactsImported()
|
|
}
|
|
}
|
|
|
|
|
|
private func fetchContactsWithEmailFromDevice() -> [CNContact] {
|
|
private func fetchContactsWithEmailFromDevice() -> [CNContact] {
|
|
@@ -55,23 +57,23 @@ class DeviceContactsHandler {
|
|
return fetchedContacts
|
|
return fetchedContacts
|
|
}
|
|
}
|
|
|
|
|
|
- public func importDeviceContacts(delegate: DeviceContactsDelegate?) {
|
|
|
|
|
|
+ public func importDeviceContacts() {
|
|
switch CNContactStore.authorizationStatus(for: .contacts) {
|
|
switch CNContactStore.authorizationStatus(for: .contacts) {
|
|
case .authorized:
|
|
case .authorized:
|
|
addContactsToCore()
|
|
addContactsToCore()
|
|
- delegate?.accessGranted()
|
|
|
|
|
|
+ self.contactListDelegate?.accessGranted()
|
|
case .denied:
|
|
case .denied:
|
|
- delegate?.accessDenied()
|
|
|
|
|
|
+ self.contactListDelegate?.accessDenied()
|
|
case .restricted, .notDetermined:
|
|
case .restricted, .notDetermined:
|
|
store.requestAccess(for: .contacts) { [unowned self] granted, _ in
|
|
store.requestAccess(for: .contacts) { [unowned self] granted, _ in
|
|
if granted {
|
|
if granted {
|
|
DispatchQueue.main.async {
|
|
DispatchQueue.main.async {
|
|
self.addContactsToCore()
|
|
self.addContactsToCore()
|
|
- delegate?.accessGranted()
|
|
|
|
|
|
+ self.contactListDelegate?.accessGranted()
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
DispatchQueue.main.async {
|
|
DispatchQueue.main.async {
|
|
- delegate?.accessDenied()
|
|
|
|
|
|
+ self.contactListDelegate?.accessDenied()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|