From df9e75d1f909dda6b34ad58b566149cff41e1a99 Mon Sep 17 00:00:00 2001 From: Achintya Ashok Date: Sun, 28 Jan 2018 18:56:44 -0500 Subject: [PATCH 1/3] Give the ability to customize the message for contacts access, if it isn't authorized. Also, added the capability to take the user directly to settings to allow access. --- Pods/EPContactsPicker.swift | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Pods/EPContactsPicker.swift b/Pods/EPContactsPicker.swift index d4d333b..0e3c25d 100644 --- a/Pods/EPContactsPicker.swift +++ b/Pods/EPContactsPicker.swift @@ -49,6 +49,9 @@ open class EPContactsPicker: UITableViewController, UISearchResultsUpdating, UIS var subtitleCellValue = SubtitleCellValue.phoneNumber var multiSelectEnabled: Bool = false //Default is single selection contact + // Customizable + var contactsAccessMessage: String? /// This is the message that the user will see when we need to request access for contacts + // MARK: - Lifecycle Methods override open func viewDidLoad() { @@ -155,8 +158,11 @@ open class EPContactsPicker: UITableViewController, UISearchResultsUpdating, UIS //User has denied the current app to access the contacts. let productName = Bundle.main.infoDictionary!["CFBundleName"]! - - let alert = UIAlertController(title: "Unable to access contacts", message: "\(productName) does not have access to contacts. Kindly enable it in privacy settings ", preferredStyle: UIAlertControllerStyle.alert) + var message: String = "\(productName) does not have access to contacts. Kindly enable it in privacy settings." + if(self.contactsAccessMessage != nil) { + message = self.contactsAccessMessage! + } + let alert = UIAlertController(title: "Unable to access contacts", message: message, preferredStyle: UIAlertControllerStyle.alert) let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: { action in completion([], error) self.dismiss(animated: true, completion: { @@ -164,6 +170,10 @@ open class EPContactsPicker: UITableViewController, UISearchResultsUpdating, UIS }) }) alert.addAction(okAction) + // Quick link for the user to reach the app's settings. + alert.addAction(UIAlertAction(title: "Open Settings", style: .default) { action in + UIApplication.shared.openURL(URL(string: UIApplicationOpenSettingsURLString)!) + }) self.present(alert, animated: true, completion: nil) case CNAuthorizationStatus.notDetermined: From 066d9de1fc2b6aa8eaa757681087a016b39eafad Mon Sep 17 00:00:00 2001 From: Achintya Ashok Date: Sun, 28 Jan 2018 19:12:27 -0500 Subject: [PATCH 2/3] Setting public access to that member --- Pods/EPContactsPicker.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pods/EPContactsPicker.swift b/Pods/EPContactsPicker.swift index 0e3c25d..c4b105b 100644 --- a/Pods/EPContactsPicker.swift +++ b/Pods/EPContactsPicker.swift @@ -50,7 +50,7 @@ open class EPContactsPicker: UITableViewController, UISearchResultsUpdating, UIS var multiSelectEnabled: Bool = false //Default is single selection contact // Customizable - var contactsAccessMessage: String? /// This is the message that the user will see when we need to request access for contacts + public var contactsAccessMessage: String? /// This is the message that the user will see when we need to request access for contacts // MARK: - Lifecycle Methods From 37f4acfc4598638bad3891b4c80dabb0cabf7d07 Mon Sep 17 00:00:00 2001 From: Achintya Ashok Date: Sun, 28 Jan 2018 23:16:17 -0500 Subject: [PATCH 3/3] Adding deslection property to delegate protocol. Also now we can set the selected contacts before loading the picker. --- Pods/EPContactsPicker.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Pods/EPContactsPicker.swift b/Pods/EPContactsPicker.swift index c4b105b..60b8005 100644 --- a/Pods/EPContactsPicker.swift +++ b/Pods/EPContactsPicker.swift @@ -14,6 +14,7 @@ public protocol EPPickerDelegate: class { func epContactPicker(_: EPContactsPicker, didContactFetchFailed error: NSError) func epContactPicker(_: EPContactsPicker, didCancel error: NSError) func epContactPicker(_: EPContactsPicker, didSelectContact contact: EPContact) + func epContactPicker(_: EPContactsPicker, didDeselectContact contact: EPContact) func epContactPicker(_: EPContactsPicker, didSelectMultipleContacts contacts: [EPContact]) } @@ -133,6 +134,13 @@ open class EPContactsPicker: UITableViewController, UISearchResultsUpdating, UIS subtitleCellValue = subtitleCellType } + convenience public init(delegate: EPPickerDelegate?, multiSelection : Bool, subtitleCellType: SubtitleCellValue, selectedContacts: [EPContact]) { + self.init(style: .plain) + self.multiSelectEnabled = multiSelection + self.contactDelegate = delegate + self.subtitleCellValue = subtitleCellType + self.selectedContacts = selectedContacts + } // MARK: - Contact Operations @@ -294,6 +302,7 @@ open class EPContactsPicker: UITableViewController, UISearchResultsUpdating, UIS //Keeps track of enable=ing and disabling contacts if cell.accessoryType == UITableViewCellAccessoryType.checkmark { cell.accessoryType = UITableViewCellAccessoryType.none + self.contactDelegate?.epContactPicker(self, didDeselectContact: selectedContact) selectedContacts = selectedContacts.filter(){ return selectedContact.contactId != $0.contactId }