简体   繁体   English

NSMutableAttributedString的问题

[英]Issue with NSMutableAttributedString

We are currently in beta testing of a new app where i am getting some crashes that i don't understand. 目前,我们正在对一个新应用进行Beta测试,但我遇到了一些我不了解的崩溃问题。 It doesn't happen on my device or simulator, but does crash on a few devices in the field we have deployed for testing. 它不会在我的设备或模拟器上发生,但会在我们部署用于测试的现场的一些设备上崩溃。 The code related to this is: 与此相关的代码是:

@implementation NSMutableAttributedString (Helper)

-(NSRange)appendString:(NSString *)string withAttributes:(NSDictionary *)attributes {

     if (![self respondsToSelector:@selector(length)]) {
         DDLogError(@"SELF can't respond to length selector. Wonder what is going on here... \n%@", [NSThread callStackSymbols]);
         DDLogError(@"SELF is of type %@", [self class]);
     }

     NSUInteger loc = self.length;
     if (string == nil) return NSMakeRange(loc, 0);

     if (![string isKindOfClass:[NSString class]]) {
         DDLogError(@"Got a non string in my appendString function.  Wonder what is going on here... \n%@", [NSThread callStackSymbols]);
         DDLogError(@"string is of type %@", [string class]);
         return NSMakeRange(loc, 0);
     }




     [self.mutableString appendString:string];
     NSRange ret = NSMakeRange(loc, string.length);
     if (attributes != nil) [self addAttributes:attributes range:ret];
     return ret;
}

-(NSRange)appendString:(NSString *)string {    
     return [self appendString:string withAttributes:nil]; // THIS IS LINE 40!
}
@end

The crash log looks like: 崩溃日志如下所示:

Incident Identifier: F9945D73-60D1-438D-B2CE-76634A501D69
CrashReporter Key:   91DBE709-85A2-4F9E-AF82-6D7C0248F443
Hardware Model:      iPhone3,1
Process:         HDScores [152]
Path:            /Users/USER/HDScores.app/HDScores
Identifier:      com.hdscores.consumer.service.clients.ios
Version:         1.23
Code Type:       ARM
Parent Process:  launchd [1]

Date/Time:       2014-07-16T19:56:43Z
OS Version:      iPhone OS 7.1.2 (11D257)
Report Version:  104

Exception Type:  SIGSEGV
Exception Codes: SEGV_ACCERR at 0x6570706d
Crashed Thread:  0

Application Specific Information:
objc_msgSend() selector name: length

Thread 0 Crashed:
0   libobjc.A.dylib                      0x3a33d626 objc_msgSend + 6
1   TextToSpeech                         0x374a0431 TTSCopyModificationDateForFileAtURL + 1610
2   HDScores                             0x00030935 -[NSMutableAttributedString(Helper) appendString:] (NSMutableAttributedString+Helper.m:40)
3   HDScores                             0x00037fe7 -[EstablishmentDetailViewController viewDidLoad] (EstablishmentDetailViewController.m:170)
4   UIKit                                0x323a44ab -[UIViewController loadViewIfRequired] + 516
5   UIKit                                0x3244ebe1 -[UINavigationController _layoutViewController:] + 30
6   UIKit                                0x3244eaf7 -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 228
7   UIKit                                0x3244e0d3 -[UINavigationController _startTransition:fromViewController:toViewController:] + 76
8   UIKit                                0x3244ddfd -[UINavigationController _startDeferredTransitionIfNeeded:] + 570
9   UIKit                                0x3244db6d -[UINavigationController __viewWillLayoutSubviews] + 42
10  UIKit                                0x3244db05 -[UILayoutContainerView layoutSubviews] + 182
11  UIKit                                0x025d1ab3 0x2580000 + 334515
12  UIKit                                0x3239fd59 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 378
13  QuartzCore                           0x3201d62b -[CALayer layoutSublayers] + 140
14  QuartzCore                           0x32018e3b CA::Layer::layout_if_needed(CA::Transaction*) + 348
15  QuartzCore                           0x32018ccd CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 14
16  QuartzCore                           0x320186df CA::Context::commit_transaction(CA::Transaction*) + 228
17  QuartzCore                           0x320184ef CA::Transaction::commit() + 312
18  QuartzCore                           0x3201221d CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 54
19  CoreFoundation                       0x2fb4e255 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 18
20  CoreFoundation                       0x2fb4bbf9 __CFRunLoopDoObservers + 282
21  CoreFoundation                       0x2fb4bf3b __CFRunLoopRun + 728
22  CoreFoundation                       0x2fab6ebf CFRunLoopRunSpecific + 520
23  CoreFoundation                       0x2fab6ca3 CFRunLoopRunInMode + 104
24  GraphicsServices                     0x349bc663 GSEventRunModal + 136
25  UIKit                                0x3240314d UIApplicationMain + 1134
26  HDScores                             0x0003daab main (main.m:17)
27  libdyld.dylib                        0x3a840ab7 start + 0

Anyone have any ideas? 有人有想法么? I can tell you the DDLogError statements are never hit, thrown in as a last ditch to try to diagnose the issue. 我可以告诉您DDLogError语句永远不会被击中,这是最后一条沟渠,试图诊断问题。 It looks like it is sending an error because length is not a known selector. 由于长度不是已知的选择器,因此似乎正在发送错误。 Again, this appears only on iPhones, not iPads with the same code. 同样,这仅出现在iPhone上,而不出现在具有相同代码的iPad上。 and so far, only a few iPhones (one is a 5, one is a 4), all on IOS 7. Any help, i'm pulling my hair out on this one... 到目前为止,只有几部iPhone(一部是5部,一部是4部),全部都在IOS 7上使用。

Just to put this out there, the way i was able to fix the issue is i renamed my helper functions (for example, they are now named helperAppendString withAttributes etc...). 只是为了解决这个问题,我能够解决此问题的方法是重命名了我的辅助函数(例如,它们现在被命名为具有属性的helperAppendString等)。 For some reason, this fixed the issue. 由于某种原因,这解决了该问题。 From the log, it looked like it was calling some other object instance instead of the [self appendString withAttributes]... 从日志看来,它正在调用其他对象实例,而不是[self appendString withAttributes] ...

Sounds crazy, but the issue has gone away when i renamed the functions. 听起来很疯狂,但是当我重命名功能时,问题就消失了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM