is there any reason why ECGraph would run fine on the simulator, but yet give me this error when i run it on my device:
2012-08-24 01:57:18.543 Portfolio[3538:9
Your device is using a different Region Format than your simulator.
If you match those (in Settings -> General -> International
), then they should show the same result. In my case, when doing this, they both failed, but the simulator didn't give the same log as the device so I nearly missed it.
I assume you are using an NSDateFormatter
to format some string-date to NSDate as I was. In that case you have to make sure that this won't depend on what kind of region the phone is, and set the solution to always be the same, whereever you are.
[df setLocale:([[NSLocale alloc] initWithLocaleIdentifier:@"en_UK"])];
// df being the NSDateFormatter-object
This tells the formatter to format using UK standards, which was needed in my case. Enter your needed country code, i.e en_US
etc.
Sti
You are trying to get NSDateComponents from a nil NSDate like that:
NSCalendar* gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDate* fromDate = nil;
NSDate* toDate = [NSDate date];
unsigned int components = NSYearCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit | NSWeekCalendarUnit | NSWeekdayCalendarUnit | NSHourCalendarUnit;
NSDateComponents* dateComponents = [gregorian components:uintFlags fromDate:fromDate toDate:toDate options:0];
Probably a simple check can be useful:
NSDate* fromDate = nil;
NSDate* toDate = [NSDate date];
NSDateComponents* dateComponents = nil;
if(fromDate != nil)
{
NSCalendar* gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
unsigned int components = NSYearCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit | NSWeekCalendarUnit | NSWeekdayCalendarUnit | NSHourCalendarUnit;
dateComponents = [gregorian components:uintFlags fromDate:fromDate toDate:toDate options:0];
}