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];
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) {
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:NSLocalizedString(@"EDIT_CONTACT_WITHOUT_CONTACTS_PERMISSION_ALERT_TITLE", comment
@ -384,6 +391,18 @@ NS_ASSUME_NONNULL_BEGIN
[UIUtil applyDefaultSystemAppearence];
}
#pragma mark - Logging
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
- (NSString *)tag
{
return self.class.tag;
}
@end
NS_ASSUME_NONNULL_END

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

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

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

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

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

Loading…
Cancel
Save