iOS 自定义键盘抛出异常

Posted

技术标签:

【中文标题】iOS 自定义键盘抛出异常【英文标题】:iOS custom keyboard throws exception 【发布时间】:2015-11-30 20:18:20 【问题描述】:

使用 Rubymotion 开发 ios 应用程序,手头的任务是使键盘更小。由于某种原因,库存键盘是较大的版本(iOS7 之前?),而不是较新的库存键盘,后者大约短半英寸。找到了一些将“com.apple.keyboard-service”添加到 info.plist 并为自定义键盘子类化 UIInputViewController 的示例。示例:

Custom Keyboard template

似乎这可能与添加到 plist 的 NSExtension 有关。在测试项目中,ProMotion 是唯一使用的 gem。在主项目甚至是新的空项目中,我都会遇到与以下相同的错误:

    15:01 $ rake
     Build ./build/iPhoneSimulator-9.1-Development
    Create ./build/iPhoneSimulator-9.1-Development/Keyboard.app/Info.plist
  Simulate ./build/iPhoneSimulator-9.1-Development/Keyboard.app
*** Starting simulator
Type `pm_live` to enable ProMotion's live reload system.
*** You will not be able to be use the REPL until the application is activated again.
2015-11-30 15:01:38.319 Keyboard[43165:10103898] *** Assertion failure in +[UIScreen _FBSDisplayDidPossiblyConnect:withScene:andPost:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.29.5/UIScreen.m:590
2015-11-30 15:01:38.324 Keyboard[43165:10103898] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Told about <FBSDisplay: 0x10b073260; name: Main ("LCD"); scale: 2.0; displayID: 1> 
    bounds = 0, 0, 375, 667;
    seed = 1;
    tags = 0;
    pid = 0;
    hidden = NO;
, but this UIScreen: <UIScreen: 0x10b238d50; bounds = 0, 0, 375, 667; mode = <UIScreenMode: 0x10b235eb0; size = 750.000000 x 1334.000000>> already has this display: <FBSDisplay: 0x10b235020; name: Main ("LCD"); scale: 2.0; displayID: 1> 
    bounds = 0, 0, 375, 667;
    seed = 5;
    tags = 0;
    pid = 0;
    hidden = NO;
'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000102f98f45 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001003f1deb objc_exception_throw + 48
    2   CoreFoundation                      0x0000000102f98daa +[NSException raise:format:arguments:] + 106
    3   Foundation                          0x00000001020dd5ee -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198
    4   UIKit                               0x0000000100e581c3 +[UIScreen _FBSDisplayDidPossiblyConnect:withScene:andPost:] + 714
    5   UIKit                               0x0000000100b14feb -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 481
    6   FrontBoardServices                  0x000000010499ae70 __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 265
    7   FrontBoardServices                  0x00000001049b3784 -[FBSSerialQueue _performNext] + 192
    8   FrontBoardServices                  0x00000001049b3af2 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
    9   CoreFoundation                      0x0000000102ec5011 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    10  CoreFoundation                      0x0000000102ebaf3c __CFRunLoopDoSources0 + 556
    11  CoreFoundation                      0x0000000102eba3f3 __CFRunLoopRun + 867
    12  CoreFoundation                      0x0000000102eb9e08 CFRunLoopRunSpecific + 488
    13  GraphicsServices                    0x0000000104da5ad2 GSEventRunModal + 161
    14  UIKit                               0x0000000100b1930d UIApplicationMain + 171
    15  Keyboard                            0x000000010000d57f main + 111
    16  libdyld.dylib                       0x00000001044c592d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

【问题讨论】:

【参考方案1】:

我们最近也遇到了这个问题。它实际上与您加载应用程序的分辨率有关。由于 iPhone 5。应用程序将在启动时加载图像以设置应用程序的默认分辨率。资源文件夹中的 default-568h@2x.png 是正在使用的黑色图像。

google book that has info about app structure and this file

【讨论】:

以上是关于iOS 自定义键盘抛出异常的主要内容,如果未能解决你的问题,请参考以下文章

iOS 8 自定义键盘

如何更改iOS自定义键盘的高度?

iOS自定义数字键盘

设备上的 iOS 8 自定义键盘

ios) 如何在自定义键盘上方创建建议视图

用于自定义键盘的 iOS 键盘关闭按钮