I'm looking at this wikipedia article:
http://en.wikipedia.org/wiki/Day_length
http://en.wikipedia.org/wiki/Sunrise_equation
Anybody had experience calculating Sunrise/Sunset times on iOS using the equations above with latitude given by the GPS?
I'm also interested in the Solar Noon. The idea is to create a clock in which the sun revolves around a fixed button, indicating time in a truly "analog" sense... The Sunrise/sunset times would then allow me to position the orbit of the "sun" around the button for a given day of the year, giving the impression of how much daylight time there will be, and how much has already expired.
Somehow iPhone adjusts brightness automatically, do you know if that is based on the ambient light via light sensor or some kind of calculation like the one that I'm trying to do above? Maybe there's already something out there that I can use?
Thank you, I'm sure this information will benefit not just me!
I found this source in C++, but am not sure how to integrate it into an existing Xcode project.
http://www.sci.fi/~benefon/rscalc_cpp.html
Here is a objective-c framework to calculate sunrise and sunset based on the location.
The iPhone adjusts its brightness by a sensor detecting ambient light.
I know that there is a method [NSDate date] which returns current date and time from iPhone clock. But if this clock time was changed manually it would rune my code.
Is there any opportunity to get world time, not current time from iPhone?
Yes, you can have correct current time by using ntp/sntp.
Following uris might help you to write your own implementation:
Simple NTP client for iOS : http://code.google.com/p/ios-ntp/
NSDate from time server: http://pathoneycutt.com/2010/12/nsdate-from-time-server/
I want sync data from iphone to the webs server. My question is how can I know which data is new? the only way I see this is by making a datafield for each record on the server and the iPhone, but how about if the Iphone user is in a different timezone or his datetime is different from the server datetime.
Store all of your dates in GMT on both the server and device. There are several methods for getting GMT easily in Objective-C. The device will determine time-zone based on location. If you need to convert to local time, you can get the date by using the NSTimeZoneClass:
[NSDate dateWithTimeIntervalSinceNow:[[NSTimeZone defaultTimeZone] secondsFromGMT]]
Check out the docs on Date and Time Programming for additional assistance.
How to find out the current time in different timezone in xcode for an iphone application?
Suppose i'm in India and i want to know the current time in USA how do i get the time then.
Thanks in advance
Joy
See Introduction to Date and Time Programming Guide for Cocoa.
There are built-in methods for handling timezones.
I need to ensure that my app gets the correct time, not the time set by the user in settings.
So for instance, once the user starts the app, I'd want to get a timestamp. The user would see the elapsed time on a timer on screen updated every second. When the user exits the app, and after some time restarts the app , the timer would just get the current time and compare it with the original timestamp it kept. So basically, just like the stopwatch in the Clock.App on iPhone.
Now the problem with the clock.app is that if the user goes and advances the time in Settings by one hour, this will influence the timer. Obviously I don't want that, because in my app, that would be cheating.
I'd need to get a more trustworthy time source to compare to.
I could get the time from the internet. But the problem is that I'd need internet connection , so only works on if there is an internet connection. My app needs to work offline preferably.
Is there some kind of internal clock I can access?
Is there a way of checking whether the user has changed the date time in Settings?
Any other ideas?
Thanks
Get the time from NIST with the Daytime Protocol:
UDP Based Daytime Service
A server listens for UDP datagrams on UDP port 13. When a datagram is received, an answering datagram is sent containing the current date and time as a ASCII character string (the data in the received datagram is ignored).
NIST Format of response: JJJJJ YR-MO-DA HH:MM:SS TT L H msADV UTC(NIST) OTM
http://tf.nist.gov/service/its.htm
http://tf.nist.gov/tf-cgi/servers.cgi
The best solution I've come up with is using the mach timer which counts time units since last iphone boot.
This works great. The only restriction is that the user cannot be allowed to reboot or it would invalidate his time.
I detect a reboot by initially storing the iphone timestamp associated with the mach timer and then checking every time the app starts, so it hasn't changed. This has as a side effect that if the user changes iPhone DateTime while he's being timed , that will also invalidate the score, but that is ok.
How can I detect whether the iphone has been rebooted since last time app started
I can easily warn my users about this: rebooting or changing iphone time while you're on the clock will invalidate your scored time.
I just posted the following here:
This works to get the GPS time:
#import <CoreLocation/CoreLocation.h>
CLLocation* gps = [[CLLocation alloc]
initWithLatitude:(CLLocationDegrees) 0.0
longitude:(CLLocationDegrees) 0.0];
NSDate* now = gps.timestamp;
It doesn't seem to be tamper-proof though.
I tried this code on an iPhone 4 in airplane mode (iOS 6.1), and even then it gives a time all right. But unfortunately this time seems to change with the system clock. Ugh.
Funny thing that I found (still in airplane mode) is that if you tamper with the system clock (after turning to off Time & Date's Set Automatically), and then turn Set Automatically back to on, the machine restores the real (original) time without a hitch. this works even after cycling the phone's power. So it seems that there is something like a tamper-proof time the device maintains internally. But how to access this?
This method will find the actual current time, found in google.com's response header:
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]
initWithURL:[NSURL URLWithString:#"http://google.com"]];
[request setHTTPMethod:#"GET"];
NSHTTPURLResponse *httpResponse = nil;
[NSURLConnection sendSynchronousRequest:request returningResponse:&httpResponse error:nil];
NSString *dateString = [[httpResponse allHeaderFields] objectForKey:#"Date"];
NSDate *currentDate = [NSDate dateWithNaturalLanguageString:dateString locale:NSLocale.currentLocale];