[英]Method Swizzle Crash: Vietnamese keyboard failing and crashing
编辑:前缀为“方法Swizzle崩溃”的问题,以帮助其他人找到错误。
对于模拟器或运行iOS 4或更高版本的任何设备上的越南语键盘中按下的每个键,以下消息将打印到控制台,并且没有字符发送给第一响应者:
Can't find transliterator file: vi_TelexTransliterator
utrans_transUChars error U_ILLEGAL_ARGUMENT_ERROR
我的服务器或客户端代码中没有这些字符串或子字符串的实例。 这来自API。
在第二次按键时,运行iOS 4的模拟器和设备将始终崩溃。 在iOS 5上没有崩溃。调用堆栈顶部的错误如下所示:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFString substringToIndex:]: Range or index out of bounds'
调用堆栈如下所示:
Foundation -[NSString substringToIndex:]
TextInput -[TIKeyboardInputManagerZephyr internalIndexToExternal:]
TextInput -[TIKeyboardInputManagerZephyr inputCount]
UIKit -[UIKeyboardImpl addInputString:fromVariantKey:]
UIKit -[UIKeyboardImpl handleStringInput:fromVariantKey:]
UIKit -[UIKeyboardImpl handleKeyEvent:]
UIKit -[UIApplication _handleKeyEvent:]
UIKit -[UIResponder(Internal) _handleKeyEvent:]
UIKit -[UIResponder(Internal) _handleKeyEvent:]
UIKit -[UIResponder(Internal) _handleKeyEvent:]
UIKit -[UIResponder(Internal) _handleKeyEvent:]
UIKit -[UIResponder(Internal) _handleKeyEvent:]
UIKit -[UIResponder(Internal) _handleKeyEvent:]
UIKit -[UIResponder(Internal) _handleKeyEvent:]
UIKit -[UIResponder(Internal) _handleKeyEvent:]
UIKit -[UIResponder(Internal) _handleKeyEvent:]
UIKit -[UIResponder(Internal) _handleKeyEvent:]
UIKit -[UIApplication handleKeyEvent:]
UIKit -[UIKeyboardLayoutStar sendStringAction:forKey:]
UIKit -[UIKeyboardLayoutStar touchUp:]
UIKit -[UIKeyboardLayout touchesEnded:withEvent:]
UIKit -[UIWindow _sendTouchesForEvent:]
UIKit -[UIWindow sendEvent:]
UIKit -[UIApplication sendEvent:]
UIKit _UIApplicationHandleEvent
GraphicsServices PurpleEventCallback
CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__
CoreFoundation __CFRunLoopDoSource1
CoreFoundation __CFRunLoopRun
CoreFoundation CFRunLoopRunSpecific
CoreFoundation CFRunLoopRunInMode
GraphicsServices GSEventRunModal
GraphicsServices GSEventRun
UIKit -[UIApplication _run]
UIKit UIApplicationMain
APP main (main.m:XXX)
我已经在整个应用程序的多个位置尝试过该键盘,包括在加载主视图之前在安全屏幕上以及在其委托中注释了所有输入处理方法的键盘上。 故障是一致的。 当实现委托方法并且我逐步执行textField:shouldChangeCharactersInRange:replacementString:时,收到的字符串是有效的。
一切似乎都表明这是一个Apple问题,但我在网上找不到其他有关此问题的报告。 我的直觉说这是我的代码中的东西。 任何人都可以提供提示吗?
该答案中的信息对于使用方法混淆时遇到类似问题的人员将是最有用的。 有关方法混淆的说明,请转到此处 。
我在NSBundle中使用pathForResource:ofType:寻找自己的方法,该方法搜索应用程序已加载的每个捆绑软件。 它还会搜索我与应用程序一起提供的资源档案。 现在解决这个问题:键盘通常从iOS内部专用的包中访问数据。 我浑浊的方法无法使用这些方法,因此键盘会间歇性地出现故障,并且没有提供任何有关原因的有用信息。
为了解决该问题,我更改了swizzled方法,以便在我的应用程序方法找不到任何资源的情况下,调用[NSBundle pathForResource:ofType:]的原始实现。
问题解决了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.