【发布时间】:2013-05-19 12:13:29
【问题描述】:
我正在尝试检测用户何时锁定设备(例如按下主页按钮)。
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
NULL, // observer
lockStateChanged, // callback
CFSTR("com.apple.springboard.lockstate"), // event name
NULL, // object
CFNotificationSuspensionBehaviorDeliverImmediately);
static void lockStateChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
NSLog(@"event received!");
// you might try inspecting the `userInfo` dictionary, to see
// if it contains any useful info
if (userInfo != nil) {
CFShow(userInfo);
}
}
我可以想象 com.apple.springboard.lockstate 就像调用私有 API 一样?或者这样可以吗?
【问题讨论】:
标签: iphone ios ipad core-foundation