ECGraph not working on device, but works on simulator

后端 未结 2 420
不思量自难忘°
不思量自难忘° 2021-01-24 18:58

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         


        
相关标签:
2条回答
  • 2021-01-24 19:00

    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

    0 讨论(0)
  • 2021-01-24 19:21

    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];
    }
    
    0 讨论(0)
提交回复
热议问题