ECGraph not working on device, but works on simulator

后端 未结 2 421
不思量自难忘°
不思量自难忘° 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: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];
    }
    

提交回复
热议问题