サブリミナル テストで、デバイスのデフォルトが原因でテキストが自動修正されるという問題が発生しています。
サブリミナルを使用してデバイス全体でオートコレクトを無効にする方法はありますか? どうにかしてデバイス設定に移動できますか?
サブリミナル テストで、デバイスのデフォルトが原因でテキストが自動修正されるという問題が発生しています。
サブリミナルを使用してデバイス全体でオートコレクトを無効にする方法はありますか? どうにかしてデバイス設定に移動できますか?
サブリミナルはデバイス設定に移動できませんが、テストでは、メソッドの入れ替えを少し行うことで、デフォルトのテキスト フィールドの自動修正タイプをオーバーライドできます。
// 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);
});
}