2

I'm having an issue coming in from Crashlytics. I have debugging parameters on so I am seeing what parameters there are.

datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 40, 0, 0)];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    NSString *startTimeString = [MathFunctions minutesToTimeString:[appointment.start_time integerValue]];
    NSLog(@"Time: %@",startTimeString);
    NSLog(@"Date: %@", appointment.date);
    [dateFormatter setDateFormat:@"yyyyMMdd h:mm a"];
    [Crashlytics setObjectValue:[NSString stringWithFormat:@"%@ %@", appointment.date, startTimeString] forKey:@"ResAddDate"];
    NSString *dateTimeString = [NSString stringWithFormat:@"%@ %@", appointment.date, startTimeString];
    NSLog(@"Date String: %@", dateTimeString);
    datePicker.date = [dateFormatter dateFromString:dateTimeString];

The crashlog coming from crashlytics shows that the date is formatted properly

RESADDDATE: 20120621 12:00 AM

The crash occurs on datePicker.date = [dateFormatter dateFromString:dateTimeString];

Why is this crashing if the date format is there and correct?

Crashlytics Log:

CoreFoundation  
__exceptionPreprocess + 162
1    libobjc.A.dylib    
objc_exception_throw + 32
2    CoreFoundation 
+[NSException raise:format:]
3    Foundation 
-[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 90
4    UIKit  
-[UIDatePickerView _updateBitsForDate:forced:andReload:animateIfNeeded:] + 146
5    UIKit  
-[UIDatePickerView _setDate:animated:forced:] + 348
6    UIKit  
-[UIDatePickerView setDate:animated:] + 30
7    UIKit  
-[UIDatePicker setDate:] + 36
8    MyApp   ReserveAddController.m line 283
-[ReserveAddController showDatePicker] + 283
9    MyApp   ReserveAddController.m line 179
-[ReserveAddController tableView:didSelectRowAtIndexPath:] + 179
10   UIKit  
-[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 944
11   UIKit  
-[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 158
12
Foundation  
__NSFireDelayedPerform + 414
13   CoreFoundation 
__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 14
14   CoreFoundation 
__CFRunLoopDoTimer + 364
15   CoreFoundation 
__CFRunLoopRun + 1206
16   CoreFoundation 
CFRunLoopRunSpecific + 300
17   CoreFoundation 
CFRunLoopRunInMode + 104
18   GraphicsServices   
GSEventRunModal + 136
19   UIKit  
UIApplicationMain + 1080
20   Appointment-Plus    main.m line 16
main + 16
21   Appointment-Plus
Bot
  • 11,868
  • 11
  • 75
  • 131
  • Can you show the crash log or trace? – Michael Frederick Jun 21 '12 at 01:04
  • UIDatePicker had an assertion failure. It's a fairly non-robust API, so this is not too surprising. It would be wise to print out the actual NSDate you're passing to UIDatePicker. Also consider that the problem may be with your setup of UIDatePicker -- that you may have initialized the spools incorrectly somehow. – Hot Licks Jun 21 '12 at 15:35
  • @HotLicks everything seems setup correctly. I cannot recreate this issue but I am getting crash reports in from users sometimes. It seems random and as you can see the date format is correct. – Bot Jun 21 '12 at 15:41
  • We don't know that NSDateFormatter parsed the date correctly. It could have returned nil, eg. – Hot Licks Jun 21 '12 at 16:17
  • (Note that you're not even showing us the "Date String" output.) – Hot Licks Jun 21 '12 at 16:19
  • (Try inserting your own assertion check that the returned NSDate is non-nil, prior to passing it to UIDataPicker.) – Hot Licks Jun 21 '12 at 16:20
  • @HotLicks I cannot show the NSLog as this is on user devices. The crash report is what I get from crashlytics but I have crashlytics logging the exact same thing as date string. You are right, I am not checking for a nil date but why does the date look correct in string format if it cannot create a date from the date formatter? – Bot Jun 21 '12 at 16:54
  • Are you sure you should only be using one 'h' in your date formatter? If it is 9:20 am does the time string contain 09:20 or 9:20? I suspect that you may be having cases where startTimeString does not match your date format. – Michael Frederick Jun 21 '12 at 17:01
  • @MichaelFrederick according to http://unicode.org/reports/tr35/tr35-10.html#Date_Format_Patterns yes. This is the page apple links to in the dev library. I do not want a leading 0. – Bot Jun 21 '12 at 17:14
  • What I am asking is if your startTimeString could have a leading zero? What are the contents of the minutesToTimeString function? – Michael Frederick Jun 21 '12 at 17:22
  • Have Crashlytics log the NSDate value. – Hot Licks Jun 21 '12 at 17:34
  • Yea I added that for next release, but since it is sporadic, it could be a few days until a crash comes in. – Bot Jun 21 '12 at 17:36

1 Answers1

8

Note that you may be getting bit by the locale "feechure". You need to set the locale of your NSDateFormatter.

Set up a phone with US locale and then set the 12/24 setting to 24. Also set a phone with European locale and then set the 12/24 setting to 12. Likely one or the other or both will fail.

Community
  • 1
  • 1
Hot Licks
  • 47,103
  • 17
  • 93
  • 151
  • 1
    you are a beast! I never thought of that. While talking to one of the guys over comments that had the crash I realize he said he was from Ireland. I set my phone to Ireland and duplicated the crash. It looks like this is the culprit. Will research and get back. – Bot Jun 22 '12 at 15:12
  • ("Feechure" is a legitimate term of the "programming arts".) – Hot Licks Jun 22 '12 at 15:43
  • Check the link above. In particular, see [this answer](http://stackoverflow.com/a/6735644/581994). – Hot Licks Jun 22 '12 at 15:47