Hide contact editing features on iOS8

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent 05d70a76df
commit 4adaaa605f

@ -303,6 +303,13 @@ NS_ASSUME_NONNULL_BEGIN
{ {
SignalAccount *signalAccount = [self signalAccountForRecipientId:recipientId]; SignalAccount *signalAccount = [self signalAccountForRecipientId:recipientId];
if (!self.contactsManager.supportsContactEditing) {
DDLogError(@"%@ Contact editing not supported.", self.tag);
// Should not expose UI that lets the user get here.
OWSAssert(NO);
return;
}
if (!self.contactsManager.isSystemContactsAuthorized) { if (!self.contactsManager.isSystemContactsAuthorized) {
UIAlertController *alertController = [UIAlertController UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:NSLocalizedString(@"EDIT_CONTACT_WITHOUT_CONTACTS_PERMISSION_ALERT_TITLE", comment alertControllerWithTitle:NSLocalizedString(@"EDIT_CONTACT_WITHOUT_CONTACTS_PERMISSION_ALERT_TITLE", comment
@ -384,6 +391,18 @@ NS_ASSUME_NONNULL_BEGIN
[UIUtil applyDefaultSystemAppearence]; [UIUtil applyDefaultSystemAppearence];
} }
#pragma mark - Logging
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
- (NSString *)tag
{
return self.class.tag;
}
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -136,7 +136,7 @@ NS_ASSUME_NONNULL_BEGIN
{ {
OWSAssert(self.thread); OWSAssert(self.thread);
if ([self.thread isKindOfClass:[TSContactThread class]]) { if ([self.thread isKindOfClass:[TSContactThread class]] && self.contactsManager.supportsContactEditing) {
self.navigationItem.rightBarButtonItem = self.navigationItem.rightBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"EDIT_TXT", nil) [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"EDIT_TXT", nil)
style:UIBarButtonItemStylePlain style:UIBarButtonItemStylePlain
@ -677,6 +677,10 @@ NS_ASSUME_NONNULL_BEGIN
- (void)presentContactViewController - (void)presentContactViewController
{ {
if (!self.contactsManager.supportsContactEditing) {
DDLogWarn(@"%@ Contact editing not supported", self.tag);
return;
}
if (![self.thread isKindOfClass:[TSContactThread class]]) { if (![self.thread isKindOfClass:[TSContactThread class]]) {
DDLogError(@"%@ unexpected thread: %@ in %s", self.tag, self.thread, __PRETTY_FUNCTION__); DDLogError(@"%@ unexpected thread: %@ in %s", self.tag, self.thread, __PRETTY_FUNCTION__);
OWSAssert(NO); OWSAssert(NO);

@ -156,15 +156,18 @@ NS_ASSUME_NONNULL_BEGIN
UIAlertController *actionSheetController = UIAlertController *actionSheetController =
[UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
NSString *contactInfoTitle = signalAccount if (self.contactsViewHelper.contactsManager.supportsContactEditing) {
? NSLocalizedString(@"GROUP_MEMBERS_VIEW_CONTACT_INFO", @"Button label for the 'show contact info' button") NSString *contactInfoTitle = signalAccount
: NSLocalizedString( ? NSLocalizedString(@"GROUP_MEMBERS_VIEW_CONTACT_INFO", @"Button label for the 'show contact info' button")
@"GROUP_MEMBERS_ADD_CONTACT_INFO", @"Button label to add information to an unknown contact"); : NSLocalizedString(
[actionSheetController addAction:[UIAlertAction actionWithTitle:contactInfoTitle @"GROUP_MEMBERS_ADD_CONTACT_INFO", @"Button label to add information to an unknown contact");
style:UIAlertActionStyleDefault [actionSheetController addAction:[UIAlertAction actionWithTitle:contactInfoTitle
handler:^(UIAlertAction *_Nonnull action) { style:UIAlertActionStyleDefault
[self showContactInfoViewForRecipientId:recipientId]; handler:^(UIAlertAction *_Nonnull action) {
}]]; [self
showContactInfoViewForRecipientId:recipientId];
}]];
}
BOOL isBlocked; BOOL isBlocked;
if (signalAccount) { if (signalAccount) {

@ -36,6 +36,8 @@ extern NSString *const OWSContactsManagerSignalAccountsDidChangeNotification;
// Must call `requestSystemContactsOnce` before accessing this method // Must call `requestSystemContactsOnce` before accessing this method
@property (nonatomic, readonly) BOOL isSystemContactsAuthorized; @property (nonatomic, readonly) BOOL isSystemContactsAuthorized;
@property (nonatomic, readonly) BOOL supportsContactEditing;
// Request systems contacts and start syncing changes. The user will see an alert // Request systems contacts and start syncing changes. The user will see an alert
// if they haven't previously. // if they haven't previously.
- (void)requestSystemContactsOnce; - (void)requestSystemContactsOnce;

@ -73,6 +73,11 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification =
return self.systemContactsFetcher.isAuthorized; return self.systemContactsFetcher.isAuthorized;
} }
- (BOOL)supportsContactEditing
{
return self.systemContactsFetcher.supportsContactEditing;
}
#pragma mark SystemContactsFetcherDelegate #pragma mark SystemContactsFetcherDelegate
- (void)systemContactsFetcher:(SystemContactsFetcher *)systemsContactsFetcher - (void)systemContactsFetcher:(SystemContactsFetcher *)systemsContactsFetcher

@ -13,6 +13,7 @@ enum Result<T, ErrorType> {
protocol ContactStoreAdaptee { protocol ContactStoreAdaptee {
var authorizationStatus: ContactStoreAuthorizationStatus { get } var authorizationStatus: ContactStoreAuthorizationStatus { get }
var supportsContactEditing: Bool { get }
func requestAccess(completionHandler: @escaping (Bool, Error?) -> Void) func requestAccess(completionHandler: @escaping (Bool, Error?) -> Void)
func fetchContacts() -> Result<[Contact], Error> func fetchContacts() -> Result<[Contact], Error>
func startObservingChanges(changeHandler: @escaping () -> Void) func startObservingChanges(changeHandler: @escaping () -> Void)
@ -24,6 +25,7 @@ class ContactsFrameworkContactStoreAdaptee: ContactStoreAdaptee {
private let contactStore = CNContactStore() private let contactStore = CNContactStore()
private var changeHandler: (() -> Void)? private var changeHandler: (() -> Void)?
private var initializedObserver = false private var initializedObserver = false
let supportsContactEditing = true
private let allowedContactKeys: [CNKeyDescriptor] = [ private let allowedContactKeys: [CNKeyDescriptor] = [
CNContactFormatter.descriptorForRequiredKeys(for: .fullName), CNContactFormatter.descriptorForRequiredKeys(for: .fullName),
@ -95,6 +97,7 @@ class AddressBookContactStoreAdaptee: ContactStoreAdaptee {
private var addressBook: ABAddressBook = ABAddressBookCreateWithOptions(nil, nil).takeRetainedValue() private var addressBook: ABAddressBook = ABAddressBookCreateWithOptions(nil, nil).takeRetainedValue()
private var changeHandler: (() -> Void)? private var changeHandler: (() -> Void)?
let supportsContactEditing = false
var authorizationStatus: ContactStoreAuthorizationStatus { var authorizationStatus: ContactStoreAuthorizationStatus {
switch ABAddressBookGetAuthorizationStatus() { switch ABAddressBookGetAuthorizationStatus() {
@ -265,6 +268,7 @@ enum ContactStoreAuthorizationStatus {
} }
class ContactStoreAdapter: ContactStoreAdaptee { class ContactStoreAdapter: ContactStoreAdaptee {
let adaptee: ContactStoreAdaptee let adaptee: ContactStoreAdaptee
init() { init() {
@ -275,6 +279,10 @@ class ContactStoreAdapter: ContactStoreAdaptee {
} }
} }
var supportsContactEditing: Bool {
return self.adaptee.supportsContactEditing
}
var authorizationStatus: ContactStoreAuthorizationStatus { var authorizationStatus: ContactStoreAuthorizationStatus {
return self.adaptee.authorizationStatus return self.adaptee.authorizationStatus
} }

Loading…
Cancel
Save