iOS 11 - disable smart quotes

Viewed 9516

iOS 11 adds smart quotes when typing. In macOS we can disable smart quotes on a NSTextView by setting:

textView.automaticQuoteSubstitutionEnabled = NO;  

Neither UITextField or UITextView seem to have this property or the enabledTextCheckingTypes property. How can smart quotes be disabled on iOS 11?

3 Answers

I don't think smartQuotesType and smartQuotesType are good practices for some languages.

Set these properties for every text inputs in our app:

if (@available(iOS 11.0, *)) {
    textView.smartDashesType = UITextSmartDashesTypeNo;
    textView.smartQuotesType = UITextSmartQuotesTypeNo;
    textView.smartInsertDeleteType = UITextSmartInsertDeleteTypeNo;
} else {
    // Fallback on earlier versions
}

Creating a category to disable these "SMART" features makes no sense (bug):

- (UITextSmartDashesType)smartDashesType {
    return UITextSmartDashesTypeNo;
}
- (UITextSmartQuotesType)smartQuotesType {
    return UITextSmartQuotesTypeNo;
}
- (UITextSmartInsertDeleteType)smartInsertDeleteType {
    return UITextSmartInsertDeleteTypeNo;
}

So I tried to disable these features permanently by method swizzling:

#import <objc/runtime.h>

@implementation DisableFuckingSmartPunctuation

+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Class class = [objc_getClass("UITextInputController") class];
        Class myClass = [self class];

        SEL originalSelector = @selector(checkSmartPunctuationForWordInRange:);
        SEL swizzledSelector = @selector(checkSmartPunctuationForWordInRange:);

        Method originalMethod = class_getInstanceMethod(class, originalSelector);
        Method swizzledMethod = class_getInstanceMethod(myClass, swizzledSelector);

        BOOL didAddMethod =
        class_addMethod(class,
                        originalSelector,
                        method_getImplementation(swizzledMethod),
                        method_getTypeEncoding(swizzledMethod));

        if (didAddMethod) {
            class_replaceMethod(class,
                                swizzledSelector,
                                method_getImplementation(originalMethod),
                                method_getTypeEncoding(originalMethod));
        } else {
            method_exchangeImplementations(originalMethod, swizzledMethod);
        }
    });
}

- (void)checkSmartPunctuationForWordInRange:(id)arg1 {

}

@end

Hacking private methods always works like a charm...

I had a problem with this - I frequently use Prompt and NX via my iPad Pro. Turning off "smart punctuation" in settings worked.

Related