EDSunriseSet returning 0

2019-08-12 12:42发布

I am using the EDSunriseSet class from https://github.com/erndev/EDSunriseSet

I have the code:

if(longitude == 0 && latitude == 0){
    longitude = 51.50722; latitude = -0.12750;
}


EDSunriseSet *sunrise = [EDSunriseSet sunrisesetWithTimezone:[NSTimeZone localTimeZone] latitude:latitude longitude:longitude];

NSLog(@"With lat = %f and long = %F; sunrise is at: %@",latitude,longitude,sunrise.localSunset);

and it returns:

<NSDateComponents: 0x10a2743a0>
Hour: 0
Minute: 0
Second: 0

Is the issue on my end or is it because the script is outdated?

1条回答
别忘想泡老子
2楼-- · 2019-08-12 13:22

So I was being rather stupid and probably should have just read the source code.

After creating the EDSunriseSet object, one must call:

[sunrise calculateSunriseSunset:[NSDate date]];

or just put:

[self calculateSunriseSunset:[NSDate date]];

into the init method if you only want to work with todays date!

查看更多
登录 后发表回答