自定义键盘在 App Store 中崩溃,但在从 Xcode 启动时不会崩溃
Custom keyboard crashes in App Store, but not in when launched from Xcode
我发现从 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
从堆栈跟踪中可以看出,您使用 UIAppearance
代理来设置应用程序的外观。
iOS 扩展的一个有趣的怪癖是,在使用此 API 的其他应用中所做的自定义实际上传递给应用中包含的扩展(至少在键盘扩展的情况下) .
为了确保安全,所有传递的对象都必须使用NSSecureCoding
进行编码,因此要求您在 UIAppearance 中使用的任何对象都必须符合此协议(并实际履行其承诺),只要用户正在您的应用中使用键盘扩展。
在这种情况下,您的应用似乎正在尝试传递无法存档的颜色。也许您正在使用 +[UIColor colorWithPatternImage:]
将图像用作颜色,这将符合错误 - 图像可能没有 UIColor 意思的颜色。
我建议您审核您的应用程序代码,找出任何使用 UIAppearance
设置颜色的实例,尤其是在使用 colorWithPatternedImage:
等奇异调用时,并将其移除。也许调配 all UIAppearance
调用无操作,在 TestFlight 中推送内部测试版,然后查看问题是否已解决以确认这是问题所在。
不管是哪一个:向 Apple 提交错误。应用程序不应仅仅因为无法正确编码 UIAppearance
而崩溃,尤其是在做一些坦率地说不受欢迎的事情时。
编辑:可以在不使用 TestFlight 的情况下重现此问题,而 运行 release
中的一个应用程序(您可以通过转到产品->方案->编辑方案来打开它)通过添加一行代码将 UIButton
的背景色设置为 UIColor
图案颜色,然后调用键盘扩展。
我发现从 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
从堆栈跟踪中可以看出,您使用 UIAppearance
代理来设置应用程序的外观。
iOS 扩展的一个有趣的怪癖是,在使用此 API 的其他应用中所做的自定义实际上传递给应用中包含的扩展(至少在键盘扩展的情况下) .
为了确保安全,所有传递的对象都必须使用NSSecureCoding
进行编码,因此要求您在 UIAppearance 中使用的任何对象都必须符合此协议(并实际履行其承诺),只要用户正在您的应用中使用键盘扩展。
在这种情况下,您的应用似乎正在尝试传递无法存档的颜色。也许您正在使用 +[UIColor colorWithPatternImage:]
将图像用作颜色,这将符合错误 - 图像可能没有 UIColor 意思的颜色。
我建议您审核您的应用程序代码,找出任何使用 UIAppearance
设置颜色的实例,尤其是在使用 colorWithPatternedImage:
等奇异调用时,并将其移除。也许调配 all UIAppearance
调用无操作,在 TestFlight 中推送内部测试版,然后查看问题是否已解决以确认这是问题所在。
不管是哪一个:向 Apple 提交错误。应用程序不应仅仅因为无法正确编码 UIAppearance
而崩溃,尤其是在做一些坦率地说不受欢迎的事情时。
编辑:可以在不使用 TestFlight 的情况下重现此问题,而 运行 release
中的一个应用程序(您可以通过转到产品->方案->编辑方案来打开它)通过添加一行代码将 UIButton
的背景色设置为 UIColor
图案颜色,然后调用键盘扩展。