自定义键盘在App Store中崩溃,但在从Xcode启动时却没有

时间:2015-12-08 16:20:04

标签: crash app-store ios9

我发现从Xcode启动时,安装和使用自定义键盘对我的应用程序运行正常,但如果我将其发布到TestFlight或AppStore,那么当用户点击文本框并尝试调出键盘时它会崩溃。据我所知,我的应用程序中的任何文本框都没有什么特别之处。堆栈跟踪是:

Thread : Fatal Exception: NSInternalInconsistencyException
0  CoreFoundation                 6512725832 __exceptionPreprocess
1  libobjc.A.dylib                6869942144 objc_exception_throw
2  CoreFoundation                 6512725528 +[NSException raise:format:]
3  Foundation                     6528403996 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:]
4  UIKit                          6606881444 -[UIColor encodeWithCoder:]
5  Foundation                     6528169072 _encodeObject
6  Foundation                     6528197336 +[NSKeyedArchiver archivedDataWithRootObject:]
7  UIKit                          6609904352 -[_UIAppearanceRecorder _recordInvocation:withClassName:containerClassNames:traitCollection:selectorString:forRemoteProcess:]
8  UIKit                          6609884356 __54+[_UIAppearance _recordersExcludingSource:withWindow:]_block_invoke
9  CoreFoundation                 6511594744 __65-[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke
10 CoreFoundation                 6511594448 -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:]
11 UIKit                          6609883592 +[_UIAppearance _recordersExcludingSource:withWindow:]
12 UIKit                          6611900724 UIViewServiceCurrentAppearanceSerializedRepresentations
13 UIKit                          6610654700 +[_UIRemoteViewController _requestViewController:traitCollection:fromServiceWithBundleIdentifier:service:connectionHandler:]
14 UIKit                          6610654160 +[_UIRemoteViewController requestViewControllerWithService:connectionHandler:]
15 UIKit                          6609355772 __117-[NSExtension(UIViewControllerAdditions) instantiateViewControllerWithInputItems:listenerEndpoint:connectionHandler:]_block_invoke_2
16 libdispatch.dylib              6878402280 _dispatch_call_block_and_release
17 libdispatch.dylib              6878402216 _dispatch_client_callout
18 libdispatch.dylib              6878424496 _dispatch_main_queue_callback_4CF
19 CoreFoundation                 6512427512 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
20 CoreFoundation                 6512418912 __CFRunLoopRun
21 CoreFoundation                 6511561888 CFRunLoopRunSpecific
22 GraphicsServices               6701891720 GSEventRunModal
23 UIKit                          6602887164 UIApplicationMain
24 MyApp                          4296179280 main (main.m:16)
25 libdyld.dylib                  6878603448 start

查看实时设备控制台,我看到以下消息:

Dec  8 15:22:11 cjhills-iPhone poc[371] <Error>: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only RGBA or White color spaces are supported in this situation.'
    *** First throw call stack:
    (0x18244cf48 0x1978f7f80 0x18244ce18 0x183340a1c 0x187e182a4 0x183307470 0x18330e2d8 0x1880fa2e0 0x1880f54c4 0x182338cf8 0x182338bac 0x1880f51c8 0x1882e1934 0x1881b15ec 0x1881b13d0 0x1880743fc 0x1981096e8 0x1981096a8 0x19810edb0 0x1824041f8 0x182402060 0x182330ca0 0x18d8b4088 0x187a48ffc 0x10014e434 0x19813a8b8)
Dec  8 15:22:11 cjhills-iPhone SpringBoard[58] <Warning>: HW kbd: Failed to set (null) as keyboard focus
Dec  8 15:22:11 cjhills-iPhone SpringBoard[58] <Warning>: HW kbd: Failed to set (null) as keyboard focus
Dec  8 15:22:11 cjhills-iPhone SwiftKey[337] <Warning>: host connection <NSXPCConnection: 0x14ce60290> connection from pid 371 invalidated
Dec  8 15:22:11 cjhills-iPhone SpringBoard[58] <Warning>: UNNotificationRegistrarConnectionListener connection invalidated
Dec  8 15:22:11 cjhills-iPhone com.apple.xpc.launchd[1] (UIKitApplication:com.cjhill.myapp[0x5a38][371]) <Notice>: Service exited due to signal: Abort trap: 6
Dec  8 15:22:11 cjhills-iPhone diagnosticd[85] <Error>: unable to find offset 0x9812fa5c in shared cache for arch 'arm64'
Dec  8 15:22:11 cjhills-iPhone ReportCrash[372] <Notice>: platform_thread_get_unique_id matched 66610
Dec  8 15:22:11 cjhills-iPhone ReportCrash[372] <Notice>: Formulating report for corpse[371] myapp
Dec  8 15:22:11 cjhills-iPhone ReportCrash[372] <Warning>: saved type '109_myapp' report (2 of max 25) as /var/mobile/Library/Logs/CrashReporter/myapp_2015-12-08-152211_cjhills-iPhone.ips
Dec  8 15:22:11 cjhills-iPhone SpringBoard[58] <Warning>: Application 'UIKitApplication:com.cjhill.myapp[0x5a38]' crashed.
Dec  8 15:22:11 cjhills-iPhone UserEventAgent[26] <Warning>: 549612077011: id=com.cjhill.myapp pid=371, state=0

1 个答案:

答案 0 :(得分:2)

从堆栈跟踪中可以看出,您使用UIAppearance个代理来设置应用程序的外观。

iOS扩展的一个有趣的怪癖是,使用此API在其他应用程序中进行的自定义实际上会传递给应用程序中包含的扩展(至少在键盘扩展的情况下)。

为确保安全性,所有传递的对象必须使用NSSecureCoding进行编码,因此要求您在UIAppearance中使用的任何对象必须符合此协议(并实际履行其承诺),只要用户是在您的应用中使用键盘扩展程序。

在这种情况下,您的应用似乎正在尝试传递无法归档的颜色。也许您使用+[UIColor colorWithPatternImage:]将图像用作颜色,这符合错误 - 图像可能没有UIColor意义上的颜色。

我建议您审核应用程序的代码,以查看使用UIAppearance设置颜色的任何实例,尤其是在使用colorWithPatternedImage:这样的异域调用时,并删除它们。也许调整all UIAppearance调用no-ops,在TestFlight中推送内部测试版,并查看问题是否已解决,以确认这是问题所在。

无论是哪一个:向Apple提交一个错误。应用程序不应该因为他们无法正确编码UIAppearance而崩溃,尤其是在做一些坦白地说是不受欢迎的事情时。

编辑:可以在不使用TestFlight的情况下重现此问题,同时在release中运行应用(您可以通过转到product-&gt; scheme-&gt;编辑方案来启用此功能),方法是添加一行代码将UIButton的背景颜色设置为图案颜色的UIColor,然后调用键盘扩展名。