【问题标题】:Disable AutoCorrect with Subliminal使用潜意识禁用自动更正
【发布时间】:2014-05-21 16:31:32
【问题描述】:

我在潜意识测试中遇到了由于设备默认设置而自动更正文本的问题。

有没有办法让我使用 Subliminal 在整个设备上禁用自动更正? 我可以以某种方式导航到设备设置吗?

【问题讨论】:

    标签: ios testing autocorrect subliminal


    【解决方案1】:

    Subliminal 无法导航到设备设置,但您的测试可以用一点method swizzling 覆盖默认文本字段自动更正类型:

    // In the test that exercises the text fields,
    // or a base test class of multiple tests that exercise text fields
    #import <objc/runtime.h>
    
    - (void)setUpTest {
        // `dispatch_once` in case this is a base test class,
        // where this method would be called multiple times
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            struct objc_method_description autocorrectionTypeMethodDescription = protocol_getMethodDescription(@protocol(UITextInputTraits), @selector(autocorrectionType), NO, YES);
            // (Re)implement `-[UITextField autocorrectionType]` to return `UITextAutocorrectionTypeNO`.
            IMP noAutocorrectionTypeIMP = imp_implementationWithBlock(^(UITextField *_self){ return UITextAutocorrectionTypeNo; });
            class_replaceMethod([UITextField class], @selector(autocorrectionType), noAutocorrectionTypeIMP, autocorrectionTypeMethodDescription.types);
        });
    }
    

    【讨论】:

      猜你喜欢
      • 2016-04-03
      • 1970-01-01
      • 2012-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-30
      • 1970-01-01
      相关资源
      最近更新 更多