0

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

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

4

1 回答 1

0

Subliminal 无法导航到设备设置,但您的测试可以通过一些方法调整来覆盖默认文本字段自动更正类型:

// 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);
    });
}
于 2014-05-24T07:43:37.567 回答