Objective-C Library for Sunrise and Sunset?

六月ゝ 毕业季﹏ 提交于 2019-12-20 09:16:50

问题


Is there an Objective-C (or C) library (that is compatible with core location) that can tell me the time of sunrise and sunset for any given calendar day?


回答1:


EDSunriseSet is an open source and free Objective-C wrapper for the C languages routines created by Paul Schlyter.

Calculation is done entirely by the C-code routines. EDSunrisetSet bridges those calculations to common Cocoa classes (NSDate, NSTimeZone, ...)




回答2:


I've actually ported the KosherJava Library and plan to make it available soon on GitHub!

Edit:

KosherCocoa is now live on GitHub! If you don't need the hebrew calendar related code, you can delete the "calendar" file. The class files are separated nicely into folders based on the kinds of calculations that they do.

Edit: KosherCocoa us due to be replaced with a modern and more complete update as soon as I can. The above link now points at a legacy repo.




回答3:


I have used a library called SUNWAIT. Very simple, effective - easy to use!




回答4:


Try this: https://github.com/mourner/suncalc/

Very clear and easy to implement, although it writen by javascript but it is easy to convert it to
objective-C

It also support for calculate sun, moon position and coordinate.




回答5:


After not finding a simple Swift alternative, I created Solar: a Swift built micro-library for Sunrise / Sunset.




回答6:


Just a note.. if you use the Berkley one... well it doesn't work (in Australia as least). It does include the Paul Schlyter C code though, which is great.

If you want it to work anywhere, best to just calc the dates in UTC.

In SunriseAndSunset.m, replace the code from double rise; double set; as follows:

sun_rise_set(theYear, theMonth, theDay, lon, lat, &rise, &set);
int hours = HOURS(rise);
int mins = MINUTES(rise);
int sethrs = HOURS(set);
int setmins = MINUTES(set);

NSTimeInterval riseOffset = ((hours * 60) + mins) * 60;
NSTimeInterval setOffset = ((sethrs * 60) + setmins) * 60;

[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
NSString *dateStr = [NSString stringWithFormat:@"%i-%02d-%02dT00:00:00+0000", theYear, theMonth, theDay];
NSDate *utcMidnight = [formatter dateFromString:dateStr];

NSDate *utcSunrise = [utcMidnight dateByAddingTimeInterval:riseOffset];
NSDate *utcSunset = [utcMidnight dateByAddingTimeInterval:setOffset];

[formatter release];
[gregorian release];

return [NSDictionary dictionaryWithObjectsAndKeys:utcSunrise, @"sunrise", utcSunset, @"sunset", nil];



回答7:


try this one: https://github.com/berkley/ObjectiveCUtil



来源:https://stackoverflow.com/questions/4102873/objective-c-library-for-sunrise-and-sunset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!