2

この呼び出し:

[UIKeyboardImpl(ShortcutConversionSupport) _shortcutConversionCandidateForInput:]

アプリがクラッシュしています。Apple の API ドキュメントをグーグルで調べても、結果は得られません。この呼び出しがアプリのどこかで行われているのを見たことがありません。また、呼び出されていると思われる場所にブレークポイントを配置しました。クラッシュレポートは次のとおりです。

(参考までに、正しい dSYM ファイルを使用しても、クラッシュ ログを完全にシンボリック化できませんでした。理由はわかりません)

Last Exception Backtrace:
0   CoreFoundation                  0x327e188f __exceptionPreprocess + 163
1   libobjc.A.dylib                 0x34837259 objc_exception_throw + 33
2   CoreFoundation                  0x327e1789 +[NSException raise:format:] + 1
3   CoreFoundation                  0x327e17ab +[NSException raise:format:] + 35
4   CoreFoundation                  0x3273bf5b -[__NSCFString substringWithRange:] + 103
5   Buffer                          0x000fa061 0xd6000 + 147553
6   UIKit                           0x32348137 -[UIKeyboardImpl(ShortcutConversionSupport) _shortcutConversionCandidateForInput:] + 615
7   UIKit                           0x32322c07 -[UIKeyboardImpl addInputString:fromVariantKey:] + 287
8   UIKit                           0x32322ae1 -[UIKeyboardImpl handleStringInput:fromVariantKey:] + 165
9   UIKit                           0x32321829 -[UIKeyboardImpl handleKeyEvent:] + 1501
10  UIKit                           0x02b10261 0x2af4000 + 115297
11  UIKit                           0x324bb8a3 -[UIKeyboardLayoutStar sendStringAction:forKey:isPopupVariant:] + 487
12  UIKit                           0x3231fdcd -[UIKeyboardLayoutStar touchUp:] + 3197
13  UIKit                           0x02b2ab47 0x2af4000 + 224071
14  UIKit                           0x3231f0fd -[UIKeyboardLayout touchesEnded:withEvent:] + 381
15  UIKit                           0x3222292b -[UIWindow _sendTouchesForEvent:] + 319
16  UIKit                           0x32222319 -[UIWindow sendEvent:] + 381
17  UIKit                           0x32208695 -[UIApplication sendEvent:] + 357
18  UIKit                           0x32207f3b _UIApplicationHandleEvent + 5827
19  GraphicsServices                0x3188f22b PurpleEventCallback + 883
20  CoreFoundation                  0x327b5523 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 39
21  CoreFoundation                  0x327b54c5 __CFRunLoopDoSource1 + 141
22  CoreFoundation                  0x327b4313 __CFRunLoopRun + 1371
23  CoreFoundation                  0x327374a5 CFRunLoopRunSpecific + 301
24  CoreFoundation                  0x3273736d CFRunLoopRunInMode + 105
25  GraphicsServices                0x3188e439 GSEventRunModal + 137
26  UIKit                           0x32236cd5 UIApplicationMain + 1081
27  Buffer                          0x000d8327 0xd6000 + 8999
28  Buffer                          0x000d7dcc 0xd6000 + 7628

substringWithRange: でクラッシュしていることは理解していますが、この特定の ShortcutConversionSupport メソッドはいつ呼び出されますか? 問題を切り分けるのに役立つと思います。

4

1 に答える 1

0

これが問題です:

- (UITextRange *)textRangeFromPosition:(UITextPosition *)fromPosition toPosition:(UITextPosition *)toPosition
{    
// Generate IndexedPosition instances that wrap the to and from ranges
    IndexedPosition *from = (IndexedPosition *)fromPosition;
    IndexedPosition *to = (IndexedPosition *)toPosition;  

    NSRange range = NSMakeRange(MIN(from.index, to.index), ABS(to.index - from.index));
    return [IndexedRange rangeWithNSRange:range];    

}

より具体的には: ABS(to.index - from.index)

問題は、to.index と from.index が両方とも NSUInteger 変数であるため (したがって、値が負になることはあり得ない)、コンパイラがこの否定の積を NSUInteger と見なすことです。したがって、from.index > to.index の場合、値はオーバーフローし、負の値ではなく 32 ビット uint の最大サイズの値が生成されます。また、ABS はtypeofを使用して積の戻り値を決定することにも注意してください。これは修正です:

- (UITextRange *)textRangeFromPosition:(UITextPosition *)fromPosition toPosition:(UITextPosition *)toPosition
{    
    IndexedPosition *from = (IndexedPosition *)fromPosition;
    IndexedPosition *to = (IndexedPosition *)toPosition;  

    NSInteger index = to.index - from.index;    
    NSRange range = NSMakeRange(MIN(from.index, to.index), ABS(index));

    return [IndexedRange rangeWithNSRange:range];

}

ちなみに、これは、ユーザーが [設定] > [一般] > [キーボード] > [ショートカット] ですべてのショートカットを削除した場合にのみ発生します。

于 2012-06-11T18:20:06.420 に答える