【问题标题】:Changing iPhone's date and time更改 iPhone 的日期和时间
【发布时间】:2013-10-17 04:35:03
【问题描述】:

我在玩 iOS SDK,并尝试以编程方式更改设备的日期和时间。 我读到使用标准 SDK 是不可能的,这是有道理的,但我想知道是否可以使用私有 API 这样做,因为我只是在做一个应用程序作为研究,并不打算发布它在 App Store 上

【问题讨论】:

  • AFAIK iPhone 将始终与运营商同步时间。也许我错了。
  • 这是一个可以关闭的选项。

标签: ios settings iphone-privateapi


【解决方案1】:

1) 将 bool 值设置为 YEScom.apple.timed 键添加到您的应用权利

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);

【讨论】:

  • 嗨。我收到以下错误:“可执行文件已使用无效权利签名”。所以我想我需要一个越狱设备?
  • 是的。此外,settimeofday 无法从沙盒应用中调用。
  • 嗨,creker,您能解释一下如何在 Xcode 中链接到 CoreTime 框架吗?
猜你喜欢
  • 1970-01-01
  • 2012-08-07
  • 1970-01-01
  • 2011-06-06
  • 1970-01-01
  • 2020-09-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多