1) Add to your app entitlements com.apple.timed
key with bool value set to YES
2) Disable automatic time setting (and timezone if you want)
Link to private CoreTime.framework
. Declare these functions
void TMSetAutomaticTimeEnabled(BOOL);
void TMSetAutomaticTimeZoneEnabled(BOOL);
Disable automatic time setting
TMSetAutomatocTimeEnabled(YES);
If you want to know in which state these settings are you can use these functions
BOOL TMIsAutomaticTimeEnabled();
BOOL TMIsAutomaticTimeZoneEnabled();
3) Change current date and time
Declare these
struct timezone
{
int tz_minutewest;
int tz_dsttime;
};
void settimeofday(struct timeval*, struct timezone*);
This API is public in OS X so you can find documentation here https://developer.apple.com/library/ios/documentation/System/Conceptual/ManPages_iPhoneOS/man2/settimeofday.2.html
As an example we will set clock 10 minutes forward
struct timeval tv;
tv.tv_sec = [[NSDate dateWithTimeIntervalSinceNow:600] timeIntervalSince1970];
tv.tv_usec = 0;
settimeofday(&tv, NULL);
4) Notify about date/time change
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("SignificantTimeChangeNotification"), NULL, NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…