我在我的潜意识测试中遇到了一些问题,由于设备默认设置,文本会被自动更正。
有没有办法让我用Subliminal禁用整个设备上的自动更正?我能以某种方式导航到设备设置吗?
发布于 2014-05-24 15:43:38
潜意识无法导航到设备设置,但您的测试可以使用一点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);
});
}https://stackoverflow.com/questions/23789015
复制相似问题