2011-10-05 103 views
0

编辑:用“方法Swizzle崩溃”作为前缀,以帮助其他人找到该错误。方法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:时,接收到的字符串是有效的。

一切似乎表明,这是一个苹果问题,但我没有发现任何其他在线问题的报告。我的直觉说这是我的代码中的东西。任何人都可以借给你一个提示吗?

+0

我刚刚为此获得了风滚草徽章。任何人都可以加入挑战吗? – AWrightIV

+0

上述信息(以及当时可用的信息)不足以找到解决方案。事实证明,这是一个更广泛的问题。它影响了3.0操作系统上的键盘以及越狱设备上的应用程序。有关决议的信息将在正式答复中提供。 – AWrightIV

回答

0

此答案中的信息对于使用方法调整时遇到类似问题的人来说最为有用。有关方法调整的解释,请参阅here

我swizzled pathForRes:ofType:在NSBundle为我自己的方法,搜索我的应用程序已加载的每个包。它还搜索我的应用程序随附的资源档案。现在的问题是:键盘通常从iOS内部专用的捆绑包中访问数据。我的混搭方法无法访问这些,所以键盘会间歇性地失败,并且不会告诉我为什么。

为了解决这个问题,我修改了swizzled方法,这样如果我的应用程序的方法找不到资源,它会调用[NSBundle pathForResource:ofType:]的原始实现。

问题解决。