2017-08-23 4 views
0

ich einen zufälligen Absturz in der folgenden Methode erlebe:iOS sigbart abbrechen Absturz

- (void) addLineToVCard:(NSMutableString **)vCard forKey:(NSString *)key setValue:(NSString *)value 
{ 
     [*vCard appendString:[NSString stringWithFormat:@"%@:%@\r\n", key, value]]; 

} 

und ich rufe dies als:

NSMutableString* vCard = [NSMutableString string]; 
[self addLineToVCard:&vCard forKey:@"BEGIN" setValue:@"VCARD"]; 
[self addLineToVCard:&vCard forKey:@"VERSION" setValue:@"3.0"]; 

Was mache ich falsch? Ich könnte das vermeiden, indem ich eine Referenz anstelle eines Zeigerobjekts übergebe. Aber ich würde gerne den Grund des Absturzes hier wissen.

Der Crash-Protokoll:

Crashed: com.apple.main-thread 
0 libsystem_kernel.dylib   0x251e6c5c __pthread_kill + 8 
1 libsystem_pthread.dylib  0x25290733 pthread_kill + 62 
2 libsystem_c.dylib    0x2517b0ad abort + 108 
3 libsystem_malloc.dylib   0x252180ad free_list_checksum_botch + 362 
4 libsystem_malloc.dylib   0x252181db free_tiny_botch + 66 
5 CoreFoundation     0x255332d3 __CFStringChangeSizeMultiple + 1838 
6 CoreFoundation     0x2553178b __CFStringCheckAndReplace + 554 
7 CoreFoundation     0x25491557 -[__NSCFString appendString:] + 26 
8 iPhoneHandheldACT    0x1ae7cf -[ContactDetailViewController addLineToVCard:forKey:setValue:] (ContactDetailViewController.m:3009) 
9 iPhoneHandheldACT    0x1ae515 -[ContactDetailViewController assembleVCard:] (ContactDetailViewController.m:2987) 
10 iPhoneHandheldACT    0x1adcbd -[ContactDetailViewController shareVCard:] (ContactDetailViewController.m:2927) 
11 iPhoneHandheldACT    0x1ad351 __47-[ContactDetailViewController btnSharePressed:]_block_invoke (ContactDetailViewController.m:2813) 
12 UIKit       0x29f2cbd9 -[UIAlertController _fireOffActionOnTargetIfValidForAction:] + 68 
13 UIKit       0x29f2d283 __85-[UIAlertController _dismissAnimated:triggeringAction:triggeredByPopoverDimmingView:]_block_invoke + 30 
14 UIKit       0x29e237e3 -[UIPresentationController transitionDidFinish:] + 1230 
15 UIKit       0x29e26a85 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke_2 + 192 
16 UIKit       0x29c04157 -[_UIViewControllerTransitionContext completeTransition:] + 90 
17 UIKit       0x29b11ba5 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 540 
18 UIKit       0x29b11685 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 204 
19 UIKit       0x29b1157f -[UIViewAnimationState animationDidStop:finished:] + 78 
20 QuartzCore      0x27b71689 CA::Layer::run_animation_callbacks(void*) + 252 
21 libdispatch.dylib    0x250c980f _dispatch_client_callout + 22 
22 libdispatch.dylib    0x250d7ba9 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1524 
23 CoreFoundation     0x2551db6d __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8 
24 CoreFoundation     0x2551c067 __CFRunLoopRun + 1574 
25 CoreFoundation     0x2546b229 CFRunLoopRunSpecific + 520 
26 CoreFoundation     0x2546b015 CFRunLoopRunInMode + 108 
27 GraphicsServices    0x26a5bac9 GSEventRunModal + 160 
28 UIKit       0x29b3f189 UIApplicationMain + 144 
29 iPhoneHandheldACT    0xcbe21 main (main.m:16) 
30 libdispatch.dylib    0x25113873 (Missing) 
+1

Nicht verwandt, aber warum verwenden Sie 'NSString stringWithFormat' mit' NSMutableString'? Verwenden Sie einfach 'appendFormat' – rmaddy

+0

Ich habe keinen Absturz von Ihrem Code bekommen. Habe einfach deinen Code kopiert und eingefügt und es funktioniert gut. –

+0

@Gagan_iOS Sie haben Recht. Es ist zufällig, dass ich nicht replizieren konnte. Das ist das Protokoll, das ich von Cryslytics bekomme. Also frage ich mich, wann das gescheitert ist. –

Antwort

1

Die Zeiger der Zeiger nicht erforderlich ist, wie folgt aus:

- (void)addLineToVCard:(NSMutableString *)vCard forKey:(NSString *)key setValue:(NSString *)value 
{ 
    [vCard appendFormat:@"%@:%@\r\n", key, value]; 
} 

dann verwenden:

NSMutableString* vCard = [NSMutableString string]; 
[self addLineToVCard:vCard forKey:@"BEGIN" setValue:@"VCARD"]; 
[self addLineToVCard:vCard forKey:@"VERSION" setValue:@"3.0"]; 

Das Ergebnis:

(lldb) po vCard 
BEGIN:VCARD 
VERSION:3.0 
+0

Und loswerden der 'stringWithFormat'. Tun Sie einfach: '[vCard appendFormat: @"% @:% @ \ r \ n ", Schlüssel, Wert];' – rmaddy

+0

@rmaddy, ja, stimme dir zu. Ich habe die Antwort so aktualisiert, wie du es gesagt hast. –