Invite Flow when "no contact"

TODO: we should probably just prevent people from getting to the invite
flow when their contacts aren't shared, but still it seems good to fix
these crashes.

// FREEBIE
pull/1/head
Michael Kirk 9 years ago
parent 40dead89e5
commit bf5b6d1e63

@ -145,20 +145,27 @@ open class ContactsPicker: UIViewController, UITableViewDelegate, UITableViewDat
func getContacts(onError errorHandler: @escaping (_ error: Error) -> Void) { func getContacts(onError errorHandler: @escaping (_ error: Error) -> Void) {
switch CNContactStore.authorizationStatus(for: CNEntityType.contacts) { switch CNContactStore.authorizationStatus(for: CNEntityType.contacts) {
case CNAuthorizationStatus.denied, CNAuthorizationStatus.restricted: case CNAuthorizationStatus.denied, CNAuthorizationStatus.restricted:
let title = NSLocalizedString("INVITE_FLOW_REQUIRES_CONTACT_ACCESS_TITLE", comment: "Alert title when contacts disabled while trying to invite contacts to signal")
let body = NSLocalizedString("INVITE_FLOW_REQUIRES_CONTACT_ACCESS_BODY", comment: "Alert body when contacts disabled while trying to invite contacts to signal")
let title = NSLocalizedString("AB_PERMISSION_MISSING_TITLE", comment: "Alert title when contacts disabled")
let body = NSLocalizedString("ADDRESSBOOK_RESTRICTED_ALERT_BODY", comment: "Alert body when contacts disabled")
let alert = UIAlertController(title: title, message: body, preferredStyle: UIAlertControllerStyle.alert) let alert = UIAlertController(title: title, message: body, preferredStyle: UIAlertControllerStyle.alert)
let dismissText = NSLocalizedString("DISMISS_BUTTON_TEXT", comment:"") let dismissText = NSLocalizedString("TXT_CANCEL_TITLE", comment:"")
let okAction = UIAlertAction(title: dismissText, style: UIAlertActionStyle.default, handler: { _ in let cancelAction = UIAlertAction(title: dismissText, style: .cancel, handler: { _ in
let error = NSError(domain: "contactsPickerErrorDomain", code: 1, userInfo: [NSLocalizedDescriptionKey: "No Contacts Access"]) let error = NSError(domain: "contactsPickerErrorDomain", code: 1, userInfo: [NSLocalizedDescriptionKey: "No Contacts Access"])
self.contactsPickerDelegate?.contactsPicker(self, didContactFetchFailed: error) self.contactsPickerDelegate?.contactsPicker(self, didContactFetchFailed: error)
errorHandler(error) errorHandler(error)
self.dismiss(animated: true, completion: nil) self.dismiss(animated: true, completion: nil)
}) })
alert.addAction(okAction) alert.addAction(cancelAction)
let settingsText = NSLocalizedString("OPEN_SETTINGS_BUTTON", comment:"Button text which opens the settings app")
let openSettingsAction = UIAlertAction(title: settingsText, style: .default, handler: { (_) in
UIApplication.shared.openSystemSettings()
})
alert.addAction(openSettingsAction)
self.present(alert, animated: true, completion: nil) self.present(alert, animated: true, completion: nil)
case CNAuthorizationStatus.notDetermined: case CNAuthorizationStatus.notDetermined:
@ -208,6 +215,10 @@ open class ContactsPicker: UIViewController, UITableViewDelegate, UITableViewDat
open func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { open func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let dataSource = filteredSections let dataSource = filteredSections
guard section < dataSource.count else {
return 0
}
return dataSource[section].count return dataSource[section].count
} }
@ -274,15 +285,15 @@ open class ContactsPicker: UIViewController, UITableViewDelegate, UITableViewDat
open func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { open func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
let dataSource = filteredSections let dataSource = filteredSections
guard dataSource.count >= section else { guard section < dataSource.count else {
return nil return nil
} }
if dataSource[section].count > 0 { if dataSource[section].count > 0 {
guard collation.sectionTitles.count >= section else { guard section < collation.sectionTitles.count else {
return nil return nil
} }
return collation.sectionTitles[section] return collation.sectionTitles[section]
} else { } else {
return nil return nil

@ -151,7 +151,7 @@ NS_ASSUME_NONNULL_BEGIN
UIButton *inviteContactsButton = [UIButton buttonWithType:UIButtonTypeCustom]; UIButton *inviteContactsButton = [UIButton buttonWithType:UIButtonTypeCustom];
[inviteContactsButton setTitle:NSLocalizedString(@"INVITE_FRIENDS_CONTACT_TABLE_BUTTON", [inviteContactsButton setTitle:NSLocalizedString(@"INVITE_FRIENDS_CONTACT_TABLE_BUTTON",
"Text for button at the top of the contact picker") "Label for the cell that presents the 'invite contacts' workflow.")
forState:UIControlStateNormal]; forState:UIControlStateNormal];
[inviteContactsButton setTitleColor:[UIColor ows_materialBlueColor] forState:UIControlStateNormal]; [inviteContactsButton setTitleColor:[UIColor ows_materialBlueColor] forState:UIControlStateNormal];
[inviteContactsButton.titleLabel setFont:[UIFont ows_regularFontWithSize:17.f]]; [inviteContactsButton.titleLabel setFont:[UIFont ows_regularFontWithSize:17.f]];
@ -420,6 +420,10 @@ NS_ASSUME_NONNULL_BEGIN
- (void)showNoContactsModeIfNecessary - (void)showNoContactsModeIfNecessary
{ {
if (!self.contactsViewHelper.contactsManager.isSystemContactsAuthorized) {
return;
}
BOOL hasNoContacts = self.contactsViewHelper.signalAccounts.count < 1; BOOL hasNoContacts = self.contactsViewHelper.signalAccounts.count < 1;
self.isNoContactsModeActive = (hasNoContacts && ![[Environment preferences] hasDeclinedNoContactsView]); self.isNoContactsModeActive = (hasNoContacts && ![[Environment preferences] hasDeclinedNoContactsView]);
} }

@ -1,9 +1,6 @@
/* Button text to dismiss missing contacts permission alert */ /* Button text to dismiss missing contacts permission alert */
"AB_PERMISSION_MISSING_ACTION_NOT_NOW" = "Not Now"; "AB_PERMISSION_MISSING_ACTION_NOT_NOW" = "Not Now";
/* Alert title when contacts disabled */
"AB_PERMISSION_MISSING_TITLE" = "Sorry!";
/* Action sheet item */ /* Action sheet item */
"ACCEPT_NEW_IDENTITY_ACTION" = "Accept new safety number"; "ACCEPT_NEW_IDENTITY_ACTION" = "Accept new safety number";
@ -22,9 +19,6 @@
/* Title for the 'add group member' view. */ /* Title for the 'add group member' view. */
"ADD_GROUP_MEMBER_VIEW_TITLE" = "Add Member"; "ADD_GROUP_MEMBER_VIEW_TITLE" = "Add Member";
/* Alert body when contacts disabled */
"ADDRESSBOOK_RESTRICTED_ALERT_BODY" = "Signal requires access to your contacts. Access to contacts is restricted. Signal will close. You can disable the restriction temporarily to let Signal access your contacts by going the Settings app >> General >> Restrictions >> Contacts >> Allow Changes.";
/* The label for the 'discard' button in alerts and action sheets. */ /* The label for the 'discard' button in alerts and action sheets. */
"ALERT_DISCARD_BUTTON" = "Discard"; "ALERT_DISCARD_BUTTON" = "Discard";
@ -580,8 +574,13 @@
/* No comment provided by engineer. */ /* No comment provided by engineer. */
"INCOMING_INCOMPLETE_CALL" = "Incomplete incoming call from"; "INCOMING_INCOMPLETE_CALL" = "Incomplete incoming call from";
/* Label for the cell that presents the 'invite contacts' workflow. /* Alert body when contacts disabled while trying to invite contacts to signal */
Text for button at the top of the contact picker */ "INVITE_FLOW_REQUIRES_CONTACT_ACCESS_BODY" = "To invite your contacts, you need to allow Signal access to your contacts in the Settings app.";
/* Alert title when contacts disabled while trying to invite contacts to signal */
"INVITE_FLOW_REQUIRES_CONTACT_ACCESS_TITLE" = "Enable Contact Access";
/* Label for the cell that presents the 'invite contacts' workflow. */
"INVITE_FRIENDS_CONTACT_TABLE_BUTTON" = "Invite Friends to Signal"; "INVITE_FRIENDS_CONTACT_TABLE_BUTTON" = "Invite Friends to Signal";
/* Search */ /* Search */

Loading…
Cancel
Save