4

私は iOS SDK をいじっています。デバイスの日付と時刻をプログラムで変更しようとしています。標準のSDKではできないと読んだのですが、これは理にかなっていますが、私は研究としてアプリをやっているだけで、公開するつもりはないので、プライベートAPIでそれが可能かどうか疑問に思っていますApp Storeで

4

1 に答える 1

8

com.apple.timed1) bool 値を に設定してアプリ資格キーに追加します。YES

2) 自動時刻設定 (必要に応じてタイムゾーンも) を無効にします。

非公開にリンクしCoreTime.frameworkます。これらの関数を宣言します

void TMSetAutomaticTimeEnabled(BOOL);
void TMSetAutomaticTimeZoneEnabled(BOOL);

自動時刻設定を無効にする

TMSetAutomatocTimeEnabled(YES);

これらの設定がどの状態であるかを知りたい場合は、これらの関数を使用できます

BOOL TMIsAutomaticTimeEnabled();
BOOL TMIsAutomaticTimeZoneEnabled();

3) 現在の日時を変更する

これらを宣言する

struct timezone
{
    int tz_minutewest;
    int tz_dsttime;
};

void settimeofday(struct timeval*, struct timezone*);

この API は OS X で公開されているため、 https://developer.apple.com/library/ios/documentation/System/Conceptual/ManPages_iPhoneOS/man2/settimeofday.2.htmlでドキュメントを見つけることができます。

例として、時計を 10 分進めます

struct timeval tv;
tv.tv_sec = [[NSDate dateWithTimeIntervalSinceNow:600] timeIntervalSince1970];
tv.tv_usec = 0;

settimeofday(&tv, NULL);

4) 日時変更のお知らせ

CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("SignificantTimeChangeNotification"), NULL, NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
于 2013-10-10T19:35:43.417 に答える