简体   繁体   English

Objective-C日出和日落图书馆?

[英]Objective-C Library for Sunrise and Sunset?

是否有一个Objective-C(或C)库(与核心位置兼容)可以告诉我任何给定日历日的日出和日落时间?

EDSunriseSet is an open source and free Objective-C wrapper for the C languages routines created by Paul Schlyter . EDSunriseSet是一个开源的免费Objective-C包装器,用于保存Schlyter创建的C语言例程。

Calculation is done entirely by the C-code routines. 计算完全由C代码例程完成。 EDSunrisetSet bridges those calculations to common Cocoa classes (NSDate, NSTimeZone, ...) EDSunrisetSet将这些计算桥接到常见的Cocoa类(NSDate,NSTimeZone,...)

I've actually ported the KosherJava Library and plan to make it available soon on GitHub! 我实际上移植了KosherJava库并计划很快在GitHub上提供它!

Edit: 编辑:

KosherCocoa is now live on GitHub! KosherCocoa现在在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. 编辑:KosherCocoa我们将尽快替换现代和更完整的更新。 The above link now points at a legacy repo. 以上链接现在指向旧版回购。

I have used a library called SUNWAIT . 我使用了一个名为SUNWAIT的库。 Very simple, effective - easy to use! 非常简单,有效 - 易于使用!

Try this: https://github.com/mourner/suncalc/ 试试这个: https//github.com/mourner/suncalc/

Very clear and easy to implement, although it writen by javascript but it is easy to convert it to 非常清晰,易于实现,虽然它是用javascript编写的,但很容易将其转换为
objective-C 客观-C

It also support for calculate sun, moon position and coordinate. 它还支持计算太阳,月亮位置和坐标。

在找不到简单的Swift替代品之后,我创建了Solar :一个Swift构建的日出/日落微库。

Just a note.. if you use the Berkley one... well it doesn't work (in Australia as least). 只是一个注意事项......如果你使用Berkley ......那么它不起作用(至少在澳大利亚)。 It does include the Paul Schlyter C code though, which is great. 它确实包括Paul Schlyter C代码,这很棒。

If you want it to work anywhere, best to just calc the dates in UTC. 如果您希望它在任何地方工作,最好只计算UTC中的日期。

In SunriseAndSunset.m, replace the code from double rise; 在SunriseAndSunset.m中,将代码替换为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];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM