Objective-C iOS 应用程序在 CFStringAppend 期间崩溃,原因不明
Objective-C iOS app crashes during CFStringAppend for unknown reason
在我的 iPhone 应用程序中,对于某些用户来说,每当他们打开某个 window 应用程序时,应用程序总是会崩溃。同样的 window 对我和其他人来说都很好,但对某些人来说总是会导致崩溃。目前还不清楚它对哪些人失败,对哪些人有效。
打开特定视图的动画 运行 没问题,但会在动画结束后立即导致崩溃。
他们已经向我发送了崩溃日志,但很难理解到底出了什么问题。我希望你能帮助我理解。崩溃日志给出的失败原因是以下异常:
Last Exception Backtrace:
0 CoreFoundation 0x1836ffd38 __exceptionPreprocess + 124
1 libobjc.A.dylib 0x182c14528 objc_exception_throw + 55
2 CoreFoundation 0x18370d1f8 -[NSObject+ 1372664 (NSObject) doesNotRecognizeSelector:] + 139
3 UIKit 0x18cec7cc4 -[UIResponder doesNotRecognizeSelector:] + 295
4 CoreFoundation 0x1837056e4 ___forwarding___ + 1379
5 CoreFoundation 0x1835eb0dc _CF_forwarding_prep_0 + 91
6 CoreFoundation 0x1835d6be8 CFStringAppend + 519
7 CoreFoundation 0x1836bddf0 __CFStringAppendFormatCore + 9271
8 CoreFoundation 0x1836bf658 _CFStringCreateWithFormatAndArgumentsAux2 + 131
9 AccessibilityUtilities 0x192d6b388 _AXStringForArgs + 279
10 UIKit 0x1a242adf8 -[UIViewControllerAccessibility viewDidAppear:] + 267
11 UIKit 0x18cb2869c -[UIViewController _setViewAppearState:isAnimating:] + 851
12 UIKit 0x18cb28c08 -[UIViewController _endAppearanceTransition:] + 227
13 UIKit 0x18cbcee00 -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 1327
14 UIKit 0x1a2440cd4 -[UINavigationControllerAccessibility navigationTransitionView:didEndTransition:fromView:toView:] + 111
15 UIKit 0x18cc96bbc __49-[UINavigationController _startCustomTransition:]_block_invoke + 251
16 UIKit 0x18cc229d8 -[_UIViewControllerTransitionContext completeTransition:] + 115
17 UIKit 0x18cd67d30 __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke.124 + 751
18 UIKit 0x18cb47d7c -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 763
19 UIKit 0x18cb4770c -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 311
20 UIKit 0x18cb47418 -[UIViewAnimationState animationDidStop:finished:] + 295
21 UIKit 0x1a2468970 -[UIViewAnimationStateAccessibility animationDidStop:finished:] + 131
22 QuartzCore 0x1876ebd6c CA::Layer::run_animation_callbacks+ 1232236 (void*) + 283
23 libdispatch.dylib 0x183085048 _dispatch_client_callout + 15
24 libdispatch.dylib 0x183091b74 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1015
25 CoreFoundation 0x1836a7f20 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 11
26 CoreFoundation 0x1836a5afc __CFRunLoopRun + 2011
27 CoreFoundation 0x1835c62d8 CFRunLoopRunSpecific + 435
28 GraphicsServices 0x185457f84 GSEventRunModal + 99
29 UIKit 0x18cb73880 UIApplicationMain + 207
30 Flyskyhy 0x10490bd80 main + 32128 (main.m:17)
31 libdyld.dylib 0x1830ea56c start + 3
崩溃日志似乎表明它在执行 CFStringAppend
时出错,但不清楚是哪个字符串有问题,或者它有什么问题,甚至不清楚为什么 CFStringAppend
是需要的。视图中可见的所有字符串在动画开始之前就已经填好了,而且都是正确的。
编辑:
根据要求,这是启动视图的代码。一切都在 NavigationController 下,因此新的视图控制器被推送到导航堆栈上以打开它。
WaypointEditController *controller = [[WaypointEditController alloc] initWithNibName:@"WayPointEdit" bundle:nil];
controller.navigationItem.title = @"New Waypoint";
// initialisation of other, custom, fields of controller
[self.navigationController pushViewController:controller animated:YES];
推送的WaypointEditController
class来源于UIViewController
。 viewWillAppear
被覆盖,以对视图的字段进行初始化。但是 - 此处相关 - viewDidAppear
未被 覆盖。
在相关情况下,以下是 viewWillAppear
方法中最重要的操作:
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
self.navigationItem.title = @"New Waypoint";
// other initialisation of internal fields
}
像你一样,我有客户报告了这个问题,我可以看到 XCode 从生产中下载的堆栈跟踪,但我无法重现它...直到我尝试启用 "voice over"。
我尝试过的其他辅助功能选项运行良好。
堆栈跟踪显示 iOS 正在将 "length" 的选择器发送到 UILabel 的实例。这看起来很奇怪。为了看看会发生什么,我向 UILabel 添加了一个 "length" 方法,以 return UILabel 文本的长度 属性。然后,它因 _encodingCantBeStoredInEightBitCFString 的未知选择器而失败。很明显 iOS 认为我的 UILabel 是某种东西,但它不是。
这最终是因为 "description" 被用作我的 UILabel property/IBOutlet 的名称。
为了解决这个问题,我将 属性 从 "description" 重命名为不同的名称。我怀疑我合成的 "description" getter 覆盖了 NSObject 的描述方法(return 是一个 NSString,它适合发送到我的 UILabel 的选择器)。
在我的 iPhone 应用程序中,对于某些用户来说,每当他们打开某个 window 应用程序时,应用程序总是会崩溃。同样的 window 对我和其他人来说都很好,但对某些人来说总是会导致崩溃。目前还不清楚它对哪些人失败,对哪些人有效。
打开特定视图的动画 运行 没问题,但会在动画结束后立即导致崩溃。
他们已经向我发送了崩溃日志,但很难理解到底出了什么问题。我希望你能帮助我理解。崩溃日志给出的失败原因是以下异常:
Last Exception Backtrace:
0 CoreFoundation 0x1836ffd38 __exceptionPreprocess + 124
1 libobjc.A.dylib 0x182c14528 objc_exception_throw + 55
2 CoreFoundation 0x18370d1f8 -[NSObject+ 1372664 (NSObject) doesNotRecognizeSelector:] + 139
3 UIKit 0x18cec7cc4 -[UIResponder doesNotRecognizeSelector:] + 295
4 CoreFoundation 0x1837056e4 ___forwarding___ + 1379
5 CoreFoundation 0x1835eb0dc _CF_forwarding_prep_0 + 91
6 CoreFoundation 0x1835d6be8 CFStringAppend + 519
7 CoreFoundation 0x1836bddf0 __CFStringAppendFormatCore + 9271
8 CoreFoundation 0x1836bf658 _CFStringCreateWithFormatAndArgumentsAux2 + 131
9 AccessibilityUtilities 0x192d6b388 _AXStringForArgs + 279
10 UIKit 0x1a242adf8 -[UIViewControllerAccessibility viewDidAppear:] + 267
11 UIKit 0x18cb2869c -[UIViewController _setViewAppearState:isAnimating:] + 851
12 UIKit 0x18cb28c08 -[UIViewController _endAppearanceTransition:] + 227
13 UIKit 0x18cbcee00 -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 1327
14 UIKit 0x1a2440cd4 -[UINavigationControllerAccessibility navigationTransitionView:didEndTransition:fromView:toView:] + 111
15 UIKit 0x18cc96bbc __49-[UINavigationController _startCustomTransition:]_block_invoke + 251
16 UIKit 0x18cc229d8 -[_UIViewControllerTransitionContext completeTransition:] + 115
17 UIKit 0x18cd67d30 __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke.124 + 751
18 UIKit 0x18cb47d7c -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 763
19 UIKit 0x18cb4770c -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 311
20 UIKit 0x18cb47418 -[UIViewAnimationState animationDidStop:finished:] + 295
21 UIKit 0x1a2468970 -[UIViewAnimationStateAccessibility animationDidStop:finished:] + 131
22 QuartzCore 0x1876ebd6c CA::Layer::run_animation_callbacks+ 1232236 (void*) + 283
23 libdispatch.dylib 0x183085048 _dispatch_client_callout + 15
24 libdispatch.dylib 0x183091b74 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1015
25 CoreFoundation 0x1836a7f20 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 11
26 CoreFoundation 0x1836a5afc __CFRunLoopRun + 2011
27 CoreFoundation 0x1835c62d8 CFRunLoopRunSpecific + 435
28 GraphicsServices 0x185457f84 GSEventRunModal + 99
29 UIKit 0x18cb73880 UIApplicationMain + 207
30 Flyskyhy 0x10490bd80 main + 32128 (main.m:17)
31 libdyld.dylib 0x1830ea56c start + 3
崩溃日志似乎表明它在执行 CFStringAppend
时出错,但不清楚是哪个字符串有问题,或者它有什么问题,甚至不清楚为什么 CFStringAppend
是需要的。视图中可见的所有字符串在动画开始之前就已经填好了,而且都是正确的。
编辑:
根据要求,这是启动视图的代码。一切都在 NavigationController 下,因此新的视图控制器被推送到导航堆栈上以打开它。
WaypointEditController *controller = [[WaypointEditController alloc] initWithNibName:@"WayPointEdit" bundle:nil];
controller.navigationItem.title = @"New Waypoint";
// initialisation of other, custom, fields of controller
[self.navigationController pushViewController:controller animated:YES];
推送的WaypointEditController
class来源于UIViewController
。 viewWillAppear
被覆盖,以对视图的字段进行初始化。但是 - 此处相关 - viewDidAppear
未被 覆盖。
在相关情况下,以下是 viewWillAppear
方法中最重要的操作:
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
self.navigationItem.title = @"New Waypoint";
// other initialisation of internal fields
}
像你一样,我有客户报告了这个问题,我可以看到 XCode 从生产中下载的堆栈跟踪,但我无法重现它...直到我尝试启用 "voice over"。
我尝试过的其他辅助功能选项运行良好。
堆栈跟踪显示 iOS 正在将 "length" 的选择器发送到 UILabel 的实例。这看起来很奇怪。为了看看会发生什么,我向 UILabel 添加了一个 "length" 方法,以 return UILabel 文本的长度 属性。然后,它因 _encodingCantBeStoredInEightBitCFString 的未知选择器而失败。很明显 iOS 认为我的 UILabel 是某种东西,但它不是。
这最终是因为 "description" 被用作我的 UILabel property/IBOutlet 的名称。
为了解决这个问题,我将 属性 从 "description" 重命名为不同的名称。我怀疑我合成的 "description" getter 覆盖了 NSObject 的描述方法(return 是一个 NSString,它适合发送到我的 UILabel 的选择器)。