Skip to content

Commit bc5870c

Browse files
Ignacio Romero ZurbuchenIgnacio Romero
authored andcommitted
Simplifies iOS 9 only API usage and fixes an issue in the sample project not compiling in iOS 8
1 parent 17a5ef4 commit bc5870c

File tree

2 files changed

+38
-45
lines changed

2 files changed

+38
-45
lines changed

Examples/Messenger-Shared/MessageViewController.m

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -191,25 +191,24 @@ - (void)simulateUserTyping:(id)sender
191191
}
192192
}
193193

194-
- (void)cellDidLongPress:(UIGestureRecognizer *)gesture
194+
- (void)didLongPressCell:(UIGestureRecognizer *)gesture
195195
{
196-
if ([UIAlertController class]) {
197-
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
198-
alertController.modalPresentationStyle = UIModalPresentationPopover;
199-
alertController.popoverPresentationController.sourceView = gesture.view.superview;
200-
alertController.popoverPresentationController.sourceRect = gesture.view.frame;
201-
202-
[alertController addAction:[UIAlertAction actionWithTitle:@"Edit Message" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
203-
[self editCellMessage:gesture];
204-
}]];
205-
206-
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:NULL]];
207-
208-
[self.navigationController presentViewController:alertController animated:YES completion:nil];
209-
}
210-
else {
196+
#ifdef __IPHONE_9_0
197+
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
198+
alertController.modalPresentationStyle = UIModalPresentationPopover;
199+
alertController.popoverPresentationController.sourceView = gesture.view.superview;
200+
alertController.popoverPresentationController.sourceRect = gesture.view.frame;
201+
202+
[alertController addAction:[UIAlertAction actionWithTitle:@"Edit Message" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
211203
[self editCellMessage:gesture];
212-
}
204+
}]];
205+
206+
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:NULL]];
207+
208+
[self.navigationController presentViewController:alertController animated:YES completion:nil];
209+
#else
210+
[self editCellMessage:gesture];
211+
#endif
213212
}
214213

215214
- (void)editCellMessage:(UIGestureRecognizer *)gesture
@@ -457,7 +456,7 @@ - (MessageTableViewCell *)messageCellForRowAtIndexPath:(NSIndexPath *)indexPath
457456
MessageTableViewCell *cell = (MessageTableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:MessengerCellIdentifier];
458457

459458
if (!cell.textLabel.text) {
460-
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(cellDidLongPress:)];
459+
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(didLongPressCell:)];
461460
[cell addGestureRecognizer:longPress];
462461
}
463462

Source/Classes/SLKTextViewController.m

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,14 +2001,12 @@ - (UIKeyCommand *)slk_returnKeyCommand
20012001
UIKeyCommand *command = [UIKeyCommand keyCommandWithInput:@"\r" modifierFlags:0 action:@selector(didPressReturnKey:)];
20022002

20032003
#ifdef __IPHONE_9_0
2004-
// Only available since iOS9
2005-
if ([UIKeyCommand respondsToSelector:@selector(keyCommandWithInput:modifierFlags:action:discoverabilityTitle:)] ) {
2006-
if (self.textInputbar.isEditing) {
2007-
command.discoverabilityTitle = [self.textInputbar.editorRightButton titleForState:UIControlStateNormal] ? : NSLocalizedString(@"Commit Editing", nil);
2008-
}
2009-
else {
2010-
command.discoverabilityTitle = [self.rightButton titleForState:UIControlStateNormal] ? : NSLocalizedString(@"Send", nil);
2011-
}
2004+
// Only available since iOS 9
2005+
if (self.textInputbar.isEditing) {
2006+
command.discoverabilityTitle = [self.textInputbar.editorRightButton titleForState:UIControlStateNormal] ? : NSLocalizedString(@"Commit Editing", nil);
2007+
}
2008+
else if (self.textView.text.length > 0) {
2009+
command.discoverabilityTitle = [self.rightButton titleForState:UIControlStateNormal] ? : NSLocalizedString(@"Send", nil);
20122010
}
20132011
#endif
20142012

@@ -2020,17 +2018,15 @@ - (UIKeyCommand *)slk_escKeyCommand
20202018
UIKeyCommand *command = [UIKeyCommand keyCommandWithInput:UIKeyInputEscape modifierFlags:0 action:@selector(didPressEscapeKey:)];
20212019

20222020
#ifdef __IPHONE_9_0
2023-
// Only available since iOS9
2024-
if ([UIKeyCommand respondsToSelector:@selector(keyCommandWithInput:modifierFlags:action:discoverabilityTitle:)] ) {
2025-
if (self.isAutoCompleting) {
2026-
command.discoverabilityTitle = NSLocalizedString(@"Exit Auto-Completion", nil);
2027-
}
2028-
else if (self.textInputbar.isEditing) {
2029-
command.discoverabilityTitle = [self.textInputbar.editorRightButton titleForState:UIControlStateNormal] ? : NSLocalizedString(@"Exit Editing", nil);
2030-
}
2031-
else if (!self.isExternalKeyboardDetected && self.keyboardHC.constant != 0) {
2032-
command.discoverabilityTitle = NSLocalizedString(@"Hide Keyboard", nil);
2033-
}
2021+
// Only available since iOS 9
2022+
if (self.isAutoCompleting) {
2023+
command.discoverabilityTitle = NSLocalizedString(@"Exit Auto-Completion", nil);
2024+
}
2025+
else if (self.textInputbar.isEditing) {
2026+
command.discoverabilityTitle = [self.textInputbar.editorRightButton titleForState:UIControlStateNormal] ? : NSLocalizedString(@"Exit Editing", nil);
2027+
}
2028+
else if (!self.isExternalKeyboardDetected && self.keyboardHC.constant != 0) {
2029+
command.discoverabilityTitle = NSLocalizedString(@"Hide Keyboard", nil);
20342030
}
20352031
#endif
20362032

@@ -2042,14 +2038,12 @@ - (UIKeyCommand *)slk_arrowKeyCommand:(NSString *)inputUpArrow
20422038
UIKeyCommand *command = [UIKeyCommand keyCommandWithInput:inputUpArrow modifierFlags:0 action:@selector(didPressArrowKey:)];
20432039

20442040
#ifdef __IPHONE_9_0
2045-
// Only available since iOS9
2046-
if ([UIKeyCommand respondsToSelector:@selector(keyCommandWithInput:modifierFlags:action:discoverabilityTitle:)] && self.textView.numberOfLines > 1) {
2047-
if ([inputUpArrow isEqualToString:UIKeyInputUpArrow]) {
2048-
command.discoverabilityTitle = NSLocalizedString(@"Move Up", nil);
2049-
}
2050-
if ([inputUpArrow isEqualToString:UIKeyInputDownArrow]) {
2051-
command.discoverabilityTitle = NSLocalizedString(@"Move Down", nil);
2052-
}
2041+
// Only available since iOS 9
2042+
if ([inputUpArrow isEqualToString:UIKeyInputUpArrow]) {
2043+
command.discoverabilityTitle = NSLocalizedString(@"Move Up", nil);
2044+
}
2045+
if ([inputUpArrow isEqualToString:UIKeyInputDownArrow]) {
2046+
command.discoverabilityTitle = NSLocalizedString(@"Move Down", nil);
20532047
}
20542048
#endif
20552049

0 commit comments

Comments
 (0)